amber-kit 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/amber.gemspec +1 -1
- data/lib/amber/http/request.rb +29 -18
- data/lib/amber/server.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abb5d6f5194b5bcc43b59ae0fe579bc79e343535
|
4
|
+
data.tar.gz: e0b86813cc0a55e49d0da869671cc1401885a86f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '018de9241807b73a26e98dc1bf0f4f8019c3e459ee83bfd79991582e8829f5735eabdfbe8ae4f42c70b5b95a80ffb4b6dfd668b7ea4ee1e2b9bd8772d4dbbfa4'
|
7
|
+
data.tar.gz: 1f44b60554f41266fd0e84069504302203cce62fc520424368e2f9468ac3c0fed8d5e711ab38bc53d15b6b8d0eb48e0e7a8bb31770eb78b7833966112d5e1ac3
|
data/amber.gemspec
CHANGED
data/lib/amber/http/request.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Amber::Http::Request < Amber::Http
|
2
|
-
attr_reader :method, :url, :query, :protocol, :body
|
2
|
+
attr_reader :method, :url, :query, :protocol, :body, :body_raw_data
|
3
3
|
|
4
4
|
GET = "GET"
|
5
5
|
POST = "POST"
|
@@ -22,8 +22,6 @@ class Amber::Http::Request < Amber::Http
|
|
22
22
|
|
23
23
|
self.receive_header
|
24
24
|
|
25
|
-
# p @header
|
26
|
-
|
27
25
|
if @header.has_key?("Content-Length")
|
28
26
|
content_length = @header["Content-Length"].to_i
|
29
27
|
|
@@ -33,7 +31,6 @@ class Amber::Http::Request < Amber::Http
|
|
33
31
|
end
|
34
32
|
|
35
33
|
# p @body_raw_data
|
36
|
-
|
37
34
|
# p @body
|
38
35
|
|
39
36
|
return true
|
@@ -43,16 +40,14 @@ class Amber::Http::Request < Amber::Http
|
|
43
40
|
last_token = ""
|
44
41
|
data = ""
|
45
42
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
break
|
50
|
-
end
|
51
|
-
|
52
|
-
data << buffer
|
53
|
-
last_token = buffer
|
43
|
+
while buffer = @socket.recv(1)
|
44
|
+
if last_token == "\r" && buffer == "\n"
|
45
|
+
break
|
54
46
|
end
|
55
|
-
|
47
|
+
|
48
|
+
data << buffer
|
49
|
+
last_token = buffer
|
50
|
+
end
|
56
51
|
|
57
52
|
self.parse_request(data)
|
58
53
|
end
|
@@ -98,8 +93,21 @@ class Amber::Http::Request < Amber::Http
|
|
98
93
|
query_info.each do |query_info_item|
|
99
94
|
query_item = query_info_item.split "="
|
100
95
|
if query_item.length == 2
|
101
|
-
query_item_key = query_item[0]
|
102
|
-
query_item_value = query_item[1]
|
96
|
+
query_item_key = URI.decode query_item[0]
|
97
|
+
query_item_value = URI.decode query_item[1]
|
98
|
+
if query_item_key.index "[]"
|
99
|
+
pure_query_item_key = query_item_key.gsub '[]', ''
|
100
|
+
if query_item_key.match /^\w+\[\]$/
|
101
|
+
query_value = @query[pure_query_item_key]
|
102
|
+
if query_value.is_a? Array
|
103
|
+
query_value.push query_item_value
|
104
|
+
else
|
105
|
+
query_value = [query_item_value]
|
106
|
+
end
|
107
|
+
@query[pure_query_item_key] = query_value
|
108
|
+
next
|
109
|
+
end
|
110
|
+
end
|
103
111
|
@query[query_item_key] = query_item_value
|
104
112
|
end
|
105
113
|
end
|
@@ -113,7 +121,7 @@ class Amber::Http::Request < Amber::Http
|
|
113
121
|
last_token = ""
|
114
122
|
data = ""
|
115
123
|
|
116
|
-
while buffer = @socket.
|
124
|
+
while buffer = @socket.recv(1)
|
117
125
|
if last_token == "\r" && buffer == "\n"
|
118
126
|
break
|
119
127
|
end
|
@@ -140,7 +148,11 @@ class Amber::Http::Request < Amber::Http
|
|
140
148
|
end
|
141
149
|
|
142
150
|
def receive_body(size)
|
143
|
-
data =
|
151
|
+
data = ""
|
152
|
+
while data.length < size
|
153
|
+
data << @socket.read(1)
|
154
|
+
end
|
155
|
+
# data = @socket.recv(size)
|
144
156
|
self.parse_body(data)
|
145
157
|
end
|
146
158
|
|
@@ -149,7 +161,6 @@ class Amber::Http::Request < Amber::Http
|
|
149
161
|
|
150
162
|
if @header.has_key?("Content-Type")
|
151
163
|
content_type = @header["Content-Type"]
|
152
|
-
|
153
164
|
if content_type.include? "application/x-www-form-urlencoded"
|
154
165
|
self.parse_form_body(data)
|
155
166
|
elsif content_type.include? "multipart/form-data"
|
data/lib/amber/server.rb
CHANGED