celluloid-http 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/celluloid-http.gemspec +1 -0
- data/lib/celluloid-http/request.rb +25 -5
- data/lib/celluloid-http/version.rb +1 -1
- data/test/unit/request_test.rb +30 -0
- metadata +17 -1
data/celluloid-http.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.add_runtime_dependency('rack')
|
21
21
|
gem.add_runtime_dependency('celluloid-io')
|
22
22
|
gem.add_runtime_dependency('http_parser.rb')
|
23
|
+
gem.add_runtime_dependency('activesupport')
|
23
24
|
|
24
25
|
gem.add_development_dependency('turn')
|
25
26
|
gem.add_development_dependency('minitest')
|
@@ -1,22 +1,42 @@
|
|
1
|
+
require 'active_support/core_ext/object/to_query'
|
2
|
+
|
1
3
|
class Celluloid::Http::Request
|
2
4
|
extend Forwardable
|
3
5
|
DEFAULT_METHOD = :get
|
4
6
|
DEFAULT_HTTP_VERSION = '1.1'
|
5
7
|
|
6
|
-
|
7
|
-
attr_accessor :method
|
8
|
+
attr_accessor :method, :body
|
8
9
|
|
9
|
-
def_delegators :@uri, :scheme, :host, :
|
10
|
+
def_delegators :@uri, :scheme, :host, :path, :port, :query
|
10
11
|
|
11
12
|
def initialize(url, options = {})
|
12
13
|
@url = url
|
13
14
|
@uri = URI.parse url
|
14
15
|
@method = options[:method] || DEFAULT_METHOD
|
16
|
+
@body = options[:body]
|
17
|
+
|
18
|
+
merge_query_params(options[:query_params]) if options[:query_params]
|
19
|
+
end
|
20
|
+
|
21
|
+
def query_params
|
22
|
+
@query_params ||= Rack::Utils.parse_nested_query @uri.query
|
15
23
|
end
|
16
24
|
|
17
25
|
def to_s
|
18
|
-
|
19
|
-
|
26
|
+
"#{method.to_s.upcase} #{url} HTTP/#{DEFAULT_HTTP_VERSION}\nHOST: #{host}\n\n"
|
27
|
+
end
|
28
|
+
|
29
|
+
def url
|
30
|
+
@uri.to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
def query=(val)
|
34
|
+
@uri.query = val.is_a?(Hash) ? val.to_query : val
|
35
|
+
end
|
36
|
+
|
37
|
+
def merge_query_params(params)
|
38
|
+
query_params.merge! params
|
39
|
+
self.query = query_params
|
20
40
|
end
|
21
41
|
|
22
42
|
end
|
data/test/unit/request_test.rb
CHANGED
@@ -16,4 +16,34 @@ class RequestTest < TestCase
|
|
16
16
|
assert_equal "param=value", request.query
|
17
17
|
end
|
18
18
|
|
19
|
+
def test_parse_query_params
|
20
|
+
request = Celluloid::Http::Request.new 'http://127.0.0.1?param1=value1¶m2=value2'
|
21
|
+
|
22
|
+
assert_equal 'value1', request.query_params['param1']
|
23
|
+
assert_equal 'value2', request.query_params['param2']
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_merge_query_params
|
27
|
+
request = Celluloid::Http::Request.new 'http://127.0.0.1?param1=value1¶m2=value2', {
|
28
|
+
query_params: {'param3' => 'value3'}
|
29
|
+
}
|
30
|
+
|
31
|
+
assert_equal 'value1', request.query_params['param1']
|
32
|
+
assert_equal 'value2', request.query_params['param2']
|
33
|
+
assert_equal 'value3', request.query_params['param3']
|
34
|
+
|
35
|
+
assert_equal 'http://127.0.0.1?param1=value1¶m2=value2¶m3=value3', request.url
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_change_query_params
|
39
|
+
request = Celluloid::Http::Request.new 'http://127.0.0.1?param1=value1¶m2=value2'
|
40
|
+
|
41
|
+
request.query = request.query_params.merge 'param3' => 'value3'
|
42
|
+
|
43
|
+
assert_equal 'value1', request.query_params['param1']
|
44
|
+
assert_equal 'value2', request.query_params['param2']
|
45
|
+
assert_equal 'value3', request.query_params['param3']
|
46
|
+
end
|
47
|
+
|
48
|
+
|
19
49
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: celluloid-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: activesupport
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
62
78
|
- !ruby/object:Gem::Dependency
|
63
79
|
name: turn
|
64
80
|
requirement: !ruby/object:Gem::Requirement
|