em-http-request 0.2.14 → 0.2.15
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of em-http-request might be problematic. Click here for more details.
- data/Changelog.md +5 -0
- data/Gemfile +15 -0
- data/Rakefile +6 -7
- data/VERSION +1 -1
- data/autotest/discover.rb +1 -0
- data/em-http-request.gemspec +3 -2
- data/ext/http11_client/http11_parser.c +418 -418
- data/ext/http11_client/http11_parser.rl +170 -170
- data/lib/em-http/client.rb +20 -4
- data/lib/em-http/multi.rb +55 -55
- data/lib/em-http/request.rb +1 -1
- data/spec/helper.rb +2 -2
- data/spec/mock_spec.rb +15 -11
- data/spec/request_spec.rb +20 -0
- data/spec/stub_server.rb +22 -22
- metadata +4 -3
- data/spec/spec.opts +0 -7
data/lib/em-http/request.rb
CHANGED
@@ -27,7 +27,7 @@ module EventMachine
|
|
27
27
|
attr_reader :options, :method
|
28
28
|
|
29
29
|
def initialize(host)
|
30
|
-
@uri = host.kind_of?(Addressable::URI) ? host : Addressable::URI::parse(host)
|
30
|
+
@uri = host.kind_of?(Addressable::URI) ? host : Addressable::URI::parse(host.to_s)
|
31
31
|
end
|
32
32
|
|
33
33
|
# Send an HTTP request and consume the response. Supported options:
|
data/spec/helper.rb
CHANGED
data/spec/mock_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe 'em-http mock' do
|
|
5
5
|
before(:all) do
|
6
6
|
EventMachine::MockHttpRequest.activate!
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
after(:all) do
|
10
10
|
EventMachine::MockHttpRequest.deactivate!
|
11
11
|
end
|
@@ -31,7 +31,7 @@ describe 'em-http mock' do
|
|
31
31
|
EventMachine.stop
|
32
32
|
}
|
33
33
|
}
|
34
|
-
|
34
|
+
|
35
35
|
EventMachine::HttpRequest.count('http://www.google.ca:80/', :get, {}).should == 1
|
36
36
|
end
|
37
37
|
|
@@ -44,7 +44,8 @@ describe 'em-http mock' do
|
|
44
44
|
http.errback { fail }
|
45
45
|
http.callback {
|
46
46
|
http.response_header.status.should == 200
|
47
|
-
http.response.should == File.read(File.join(File.dirname(__FILE__), 'fixtures', 'google.ca')).split("\r\n\r\n", 2).last
|
47
|
+
http.response.should == File.read(File.join(File.dirname(__FILE__), 'fixtures', 'google.ca'), :encoding => 'ISO-8859-1').split("\r\n\r\n", 2).last
|
48
|
+
http.response.encoding.to_s.should == 'ISO-8859-1'
|
48
49
|
EventMachine::HttpRequest.count('http://www.google.ca:80/', :get, {}).should == 1
|
49
50
|
EventMachine.stop
|
50
51
|
}
|
@@ -54,12 +55,13 @@ describe 'em-http mock' do
|
|
54
55
|
it "should serve a fake http request from a file" do
|
55
56
|
EventMachine::HttpRequest.register_file('http://www.google.ca:80/', :get, {}, File.join(File.dirname(__FILE__), 'fixtures', 'google.ca'))
|
56
57
|
EM.run {
|
57
|
-
|
58
|
+
|
58
59
|
http = EventMachine::HttpRequest.new('http://www.google.ca/').get
|
59
60
|
http.errback { fail }
|
60
61
|
http.callback {
|
61
62
|
http.response_header.status.should == 200
|
62
|
-
http.response.should == File.read(File.join(File.dirname(__FILE__), 'fixtures', 'google.ca')).split("\r\n\r\n", 2).last
|
63
|
+
http.response.should == File.read(File.join(File.dirname(__FILE__), 'fixtures', 'google.ca'), :encoding => 'ISO-8859-1').split("\r\n\r\n", 2).last
|
64
|
+
http.response.encoding.to_s.should == 'ISO-8859-1'
|
63
65
|
EventMachine::HttpRequest.count('http://www.google.ca:80/', :get, {}).should == 1
|
64
66
|
EventMachine.stop
|
65
67
|
}
|
@@ -92,7 +94,7 @@ function a(){google.timers.load.t.ol=(new Date).getTime();google.report&&google.
|
|
92
94
|
HEREDOC
|
93
95
|
EventMachine::HttpRequest.register('http://www.google.ca:80/', :get, {}, data)
|
94
96
|
EventMachine.run {
|
95
|
-
|
97
|
+
|
96
98
|
http = EventMachine::HttpRequest.new('http://www.google.ca/').get
|
97
99
|
http.errback { fail }
|
98
100
|
http.callback {
|
@@ -101,7 +103,7 @@ function a(){google.timers.load.t.ol=(new Date).getTime();google.report&&google.
|
|
101
103
|
EventMachine.stop
|
102
104
|
}
|
103
105
|
}
|
104
|
-
|
106
|
+
|
105
107
|
end
|
106
108
|
|
107
109
|
it "should serve a fake failing http request" do
|
@@ -130,24 +132,26 @@ function a(){google.timers.load.t.ol=(new Date).getTime();google.report&&google.
|
|
130
132
|
http.errback { fail }
|
131
133
|
http.callback {
|
132
134
|
http.response_header.status.should == 200
|
133
|
-
http.response.should == File.read(File.join(File.dirname(__FILE__), 'fixtures', 'google.ca')).split("\r\n\r\n", 2).last
|
135
|
+
http.response.should == File.read(File.join(File.dirname(__FILE__), 'fixtures', 'google.ca'), :encoding => 'ISO-8859-1').split("\r\n\r\n", 2).last
|
136
|
+
http.response.encoding.to_s.should == 'ISO-8859-1'
|
134
137
|
EventMachine::HttpRequest.count('http://www.google.ca:80/', :get, {}).should == 1
|
135
138
|
EventMachine::HttpRequest.count('http://www.google.ca:80/', :get, {:user_agent => 'BERT'}).should == 0
|
136
139
|
EventMachine.stop
|
137
140
|
}
|
138
141
|
}
|
139
|
-
|
142
|
+
|
140
143
|
EM.run {
|
141
144
|
http = EventMachine::HttpRequest.new('http://www.google.ca/').get({:head => {:user_agent => 'BERT'}})
|
142
145
|
http.errback { fail }
|
143
146
|
http.callback {
|
144
147
|
http.response_header.status.should == 200
|
145
|
-
http.response.should == File.read(File.join(File.dirname(__FILE__), 'fixtures', 'google.ca')).split("\r\n\r\n", 2).last
|
148
|
+
http.response.should == File.read(File.join(File.dirname(__FILE__), 'fixtures', 'google.ca'), :encoding => 'ISO-8859-1').split("\r\n\r\n", 2).last
|
149
|
+
http.response.encoding.to_s.should == 'ISO-8859-1'
|
146
150
|
EventMachine::HttpRequest.count('http://www.google.ca:80/', :get, {:user_agent => 'BERT'}).should == 1
|
147
151
|
EventMachine.stop
|
148
152
|
}
|
149
153
|
}
|
150
|
-
|
154
|
+
|
151
155
|
end
|
152
156
|
|
153
157
|
it "should raise an exception if pass-thru is disabled" do
|
data/spec/request_spec.rb
CHANGED
@@ -100,6 +100,26 @@ describe EventMachine::HttpRequest do
|
|
100
100
|
}
|
101
101
|
end
|
102
102
|
|
103
|
+
it "should redirect with missing content-length" do
|
104
|
+
EventMachine.run {
|
105
|
+
@s = StubServer.new("HTTP/1.0 301 MOVED PERMANENTLY\r\nlocation: http://127.0.0.1:8080/redirect\r\n\r\n")
|
106
|
+
|
107
|
+
http = EventMachine::HttpRequest.new('http://127.0.0.1:8081/').get :redirects => 2
|
108
|
+
http.errback { failed }
|
109
|
+
|
110
|
+
http.callback {
|
111
|
+
http.response_header.status.should == 200
|
112
|
+
http.response_header["CONTENT_ENCODING"].should == "gzip"
|
113
|
+
http.response.should == "compressed"
|
114
|
+
http.last_effective_url.to_s.should == 'http://127.0.0.1:8080/gzip'
|
115
|
+
http.redirects.should == 2
|
116
|
+
|
117
|
+
@s.stop
|
118
|
+
EM.stop
|
119
|
+
}
|
120
|
+
}
|
121
|
+
end
|
122
|
+
|
103
123
|
it "should follow redirects on HEAD method" do
|
104
124
|
EventMachine.run {
|
105
125
|
http = EventMachine::HttpRequest.new('http://127.0.0.1:8080/redirect/head').head :redirects => 1
|
data/spec/stub_server.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
class StubServer
|
2
|
-
module Server
|
3
|
-
def receive_data(data)
|
4
|
-
send_data @response
|
5
|
-
close_connection_after_writing
|
6
|
-
end
|
7
|
-
|
8
|
-
def response=(response)
|
9
|
-
@response = response
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def initialize(response, port=8081)
|
14
|
-
@sig = EventMachine::start_server("127.0.0.1", port, Server) { |s|
|
15
|
-
s.response = response
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
def stop
|
20
|
-
EventMachine.stop_server @sig
|
21
|
-
end
|
22
|
-
end
|
1
|
+
class StubServer
|
2
|
+
module Server
|
3
|
+
def receive_data(data)
|
4
|
+
send_data @response
|
5
|
+
close_connection_after_writing
|
6
|
+
end
|
7
|
+
|
8
|
+
def response=(response)
|
9
|
+
@response = response
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(response, port=8081)
|
14
|
+
@sig = EventMachine::start_server("127.0.0.1", port, Server) { |s|
|
15
|
+
s.response = response
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def stop
|
20
|
+
EventMachine.stop_server @sig
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 15
|
9
|
+
version: 0.2.15
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ilya Grigorik
|
@@ -60,10 +60,12 @@ extra_rdoc_files:
|
|
60
60
|
files:
|
61
61
|
- .gitignore
|
62
62
|
- Changelog.md
|
63
|
+
- Gemfile
|
63
64
|
- LICENSE
|
64
65
|
- README.md
|
65
66
|
- Rakefile
|
66
67
|
- VERSION
|
68
|
+
- autotest/discover.rb
|
67
69
|
- em-http-request.gemspec
|
68
70
|
- examples/fetch.rb
|
69
71
|
- examples/fibered-http.rb
|
@@ -94,7 +96,6 @@ files:
|
|
94
96
|
- spec/mock_spec.rb
|
95
97
|
- spec/multi_spec.rb
|
96
98
|
- spec/request_spec.rb
|
97
|
-
- spec/spec.opts
|
98
99
|
- spec/stallion.rb
|
99
100
|
- spec/stub_server.rb
|
100
101
|
has_rdoc: true
|