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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b2b0cde2d48a5f894ed730b36260d428de273da
4
- data.tar.gz: df73ca4d62fb83e44fde411594a1d451a3448dbe
3
+ metadata.gz: abb5d6f5194b5bcc43b59ae0fe579bc79e343535
4
+ data.tar.gz: e0b86813cc0a55e49d0da869671cc1401885a86f
5
5
  SHA512:
6
- metadata.gz: d0e02a5aa95e3fbfd6d2cf492fc333b9673a20c565e16452a99b711c3943343ac03f30279ef4bc65b30f2aa21131264bb602136d92afc858380f36f48d627d5c
7
- data.tar.gz: b2c3db8bcb7203822e8f9604a7f288a35c7a082fb825372128ad651b8718d92e0eb8be1180d3ca1d79c56d2c4734ba779c59fd739c696fe04e699b432c20fb8f
6
+ metadata.gz: '018de9241807b73a26e98dc1bf0f4f8019c3e459ee83bfd79991582e8829f5735eabdfbe8ae4f42c70b5b95a80ffb4b6dfd668b7ea4ee1e2b9bd8772d4dbbfa4'
7
+ data.tar.gz: 1f44b60554f41266fd0e84069504302203cce62fc520424368e2f9468ac3c0fed8d5e711ab38bc53d15b6b8d0eb48e0e7a8bb31770eb78b7833966112d5e1ac3
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "amber-kit"
3
- s.version = "0.0.1"
3
+ s.version = "0.0.3"
4
4
  s.authors = ["Jakit"]
5
5
  s.date = "2017-06-03"
6
6
  s.summary = "A glitter network toolkit"
@@ -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
- Timeout::timeout(30) {
47
- while buffer = @socket.recv_nonblock(1)
48
- if last_token == "\r" && buffer == "\n"
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.recv_nonblock(1)
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 = @socket.recv(size)
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"
@@ -1,7 +1,7 @@
1
1
  class Amber::Server
2
2
  attr_accessor :port, :host, :base
3
3
 
4
- def initialize(port = 3001, host = '127.0.0.1')
4
+ def initialize(port = 3001, host = '0.0.0.0')
5
5
  @port = port
6
6
  @host = host
7
7
  @server_socket
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amber-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakit