em-http-request 1.0.2 → 1.0.3
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/.gitignore +1 -0
- data/benchmarks/clients.rb +44 -30
- data/benchmarks/server.rb +3 -3
- data/em-http-request.gemspec +33 -33
- data/lib/em-http/client.rb +5 -3
- data/lib/em-http/decoders.rb +34 -12
- data/lib/em-http/http_client_options.rb +1 -2
- data/lib/em-http/http_connection.rb +12 -5
- data/lib/em-http/http_connection_options.rb +6 -1
- data/lib/em-http/http_header.rb +3 -0
- data/lib/em-http/version.rb +1 -1
- data/spec/client_fiber_spec.rb +23 -23
- data/spec/client_spec.rb +80 -10
- data/spec/external_spec.rb +150 -128
- data/spec/fixtures/gzip-sample.gz +0 -0
- data/spec/http_proxy_spec.rb +16 -0
- data/spec/pipelining_spec.rb +65 -65
- data/spec/redirect_spec.rb +15 -0
- data/spec/socksify_proxy_spec.rb +24 -24
- data/spec/stallion.rb +23 -3
- metadata +75 -23
data/spec/external_spec.rb
CHANGED
@@ -1,128 +1,150 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
requires_connection do
|
4
|
-
|
5
|
-
describe EventMachine::HttpRequest do
|
6
|
-
|
7
|
-
it "should follow redirects on HEAD method (external)" do
|
8
|
-
EventMachine.run {
|
9
|
-
http = EventMachine::HttpRequest.new('http://www.google.com/').head :redirects => 1
|
10
|
-
http.errback { failed(http) }
|
11
|
-
http.callback {
|
12
|
-
http.response_header.status.should == 200
|
13
|
-
EM.stop
|
14
|
-
}
|
15
|
-
}
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should follow redirect to https and initiate the handshake" do
|
19
|
-
EventMachine.run {
|
20
|
-
http = EventMachine::HttpRequest.new('http://analytics.postrank.com/').get :redirects => 5
|
21
|
-
|
22
|
-
http.errback { failed(http) }
|
23
|
-
http.callback {
|
24
|
-
http.response_header.status.should == 200
|
25
|
-
EventMachine.stop
|
26
|
-
}
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should perform a streaming GET" do
|
31
|
-
EventMachine.run {
|
32
|
-
|
33
|
-
# digg.com uses chunked encoding
|
34
|
-
http = EventMachine::HttpRequest.new('http://digg.com/news').get
|
35
|
-
|
36
|
-
http.errback { failed(http) }
|
37
|
-
http.callback {
|
38
|
-
http.response_header.status.should == 200
|
39
|
-
EventMachine.stop
|
40
|
-
}
|
41
|
-
}
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should handle a 100 continue" do
|
45
|
-
EventMachine.run {
|
46
|
-
# 8.2.3 Use of the 100 (Continue) Status - http://www.ietf.org/rfc/rfc2616.txt
|
47
|
-
#
|
48
|
-
# An origin server SHOULD NOT send a 100 (Continue) response if
|
49
|
-
# the request message does not include an Expect request-header
|
50
|
-
# field with the "100-continue" expectation, and MUST NOT send a
|
51
|
-
# 100 (Continue) response if such a request comes from an HTTP/1.0
|
52
|
-
# (or earlier) client. There is an exception to this rule: for
|
53
|
-
# compatibility with RFC 2068, a server MAY send a 100 (Continue)
|
54
|
-
# status in response to an HTTP/1.1 PUT or POST request that does
|
55
|
-
# not include an Expect request-header field with the "100-
|
56
|
-
# continue" expectation. This exception, the purpose of which is
|
57
|
-
# to minimize any client processing delays associated with an
|
58
|
-
# undeclared wait for 100 (Continue) status, applies only to
|
59
|
-
# HTTP/1.1 requests, and not to requests with any other HTTP-
|
60
|
-
# version value.
|
61
|
-
#
|
62
|
-
# 10.1.1: 100 Continue - http://www.ietf.org/rfc/rfc2068.txt
|
63
|
-
# The client may continue with its request. This interim response is
|
64
|
-
# used to inform the client that the initial part of the request has
|
65
|
-
# been received and has not yet been rejected by the server. The client
|
66
|
-
# SHOULD continue by sending the remainder of the request or, if the
|
67
|
-
# request has already been completed, ignore this response. The server
|
68
|
-
# MUST send a final response after the request has been completed.
|
69
|
-
|
70
|
-
url = 'http://ws.serviceobjects.com/lv/LeadValidation.asmx/ValidateLead_V2'
|
71
|
-
http = EventMachine::HttpRequest.new(url).post :body => {:name => :test}
|
72
|
-
|
73
|
-
http.errback { failed(http) }
|
74
|
-
http.callback {
|
75
|
-
http.response_header.status.should == 500
|
76
|
-
http.response.should match('Missing')
|
77
|
-
EventMachine.stop
|
78
|
-
}
|
79
|
-
}
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should detect deflate encoding" do
|
83
|
-
pending "need an endpoint which supports deflate.. MSN is no longer"
|
84
|
-
EventMachine.run {
|
85
|
-
|
86
|
-
options = {:head => {"accept-encoding" => "deflate"}, :redirects => 5}
|
87
|
-
http = EventMachine::HttpRequest.new('http://www.msn.com').get options
|
88
|
-
|
89
|
-
http.errback { failed(http) }
|
90
|
-
http.callback {
|
91
|
-
http.response_header.status.should == 200
|
92
|
-
http.response_header["CONTENT_ENCODING"].should == "deflate"
|
93
|
-
|
94
|
-
EventMachine.stop
|
95
|
-
}
|
96
|
-
}
|
97
|
-
end
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
http.
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
requires_connection do
|
4
|
+
|
5
|
+
describe EventMachine::HttpRequest do
|
6
|
+
|
7
|
+
it "should follow redirects on HEAD method (external)" do
|
8
|
+
EventMachine.run {
|
9
|
+
http = EventMachine::HttpRequest.new('http://www.google.com/').head :redirects => 1
|
10
|
+
http.errback { failed(http) }
|
11
|
+
http.callback {
|
12
|
+
http.response_header.status.should == 200
|
13
|
+
EM.stop
|
14
|
+
}
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should follow redirect to https and initiate the handshake" do
|
19
|
+
EventMachine.run {
|
20
|
+
http = EventMachine::HttpRequest.new('http://analytics.postrank.com/').get :redirects => 5
|
21
|
+
|
22
|
+
http.errback { failed(http) }
|
23
|
+
http.callback {
|
24
|
+
http.response_header.status.should == 200
|
25
|
+
EventMachine.stop
|
26
|
+
}
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should perform a streaming GET" do
|
31
|
+
EventMachine.run {
|
32
|
+
|
33
|
+
# digg.com uses chunked encoding
|
34
|
+
http = EventMachine::HttpRequest.new('http://digg.com/news').get
|
35
|
+
|
36
|
+
http.errback { failed(http) }
|
37
|
+
http.callback {
|
38
|
+
http.response_header.status.should == 200
|
39
|
+
EventMachine.stop
|
40
|
+
}
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should handle a 100 continue" do
|
45
|
+
EventMachine.run {
|
46
|
+
# 8.2.3 Use of the 100 (Continue) Status - http://www.ietf.org/rfc/rfc2616.txt
|
47
|
+
#
|
48
|
+
# An origin server SHOULD NOT send a 100 (Continue) response if
|
49
|
+
# the request message does not include an Expect request-header
|
50
|
+
# field with the "100-continue" expectation, and MUST NOT send a
|
51
|
+
# 100 (Continue) response if such a request comes from an HTTP/1.0
|
52
|
+
# (or earlier) client. There is an exception to this rule: for
|
53
|
+
# compatibility with RFC 2068, a server MAY send a 100 (Continue)
|
54
|
+
# status in response to an HTTP/1.1 PUT or POST request that does
|
55
|
+
# not include an Expect request-header field with the "100-
|
56
|
+
# continue" expectation. This exception, the purpose of which is
|
57
|
+
# to minimize any client processing delays associated with an
|
58
|
+
# undeclared wait for 100 (Continue) status, applies only to
|
59
|
+
# HTTP/1.1 requests, and not to requests with any other HTTP-
|
60
|
+
# version value.
|
61
|
+
#
|
62
|
+
# 10.1.1: 100 Continue - http://www.ietf.org/rfc/rfc2068.txt
|
63
|
+
# The client may continue with its request. This interim response is
|
64
|
+
# used to inform the client that the initial part of the request has
|
65
|
+
# been received and has not yet been rejected by the server. The client
|
66
|
+
# SHOULD continue by sending the remainder of the request or, if the
|
67
|
+
# request has already been completed, ignore this response. The server
|
68
|
+
# MUST send a final response after the request has been completed.
|
69
|
+
|
70
|
+
url = 'http://ws.serviceobjects.com/lv/LeadValidation.asmx/ValidateLead_V2'
|
71
|
+
http = EventMachine::HttpRequest.new(url).post :body => {:name => :test}
|
72
|
+
|
73
|
+
http.errback { failed(http) }
|
74
|
+
http.callback {
|
75
|
+
http.response_header.status.should == 500
|
76
|
+
http.response.should match('Missing')
|
77
|
+
EventMachine.stop
|
78
|
+
}
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should detect deflate encoding" do
|
83
|
+
pending "need an endpoint which supports deflate.. MSN is no longer"
|
84
|
+
EventMachine.run {
|
85
|
+
|
86
|
+
options = {:head => {"accept-encoding" => "deflate"}, :redirects => 5}
|
87
|
+
http = EventMachine::HttpRequest.new('http://www.msn.com').get options
|
88
|
+
|
89
|
+
http.errback { failed(http) }
|
90
|
+
http.callback {
|
91
|
+
http.response_header.status.should == 200
|
92
|
+
http.response_header["CONTENT_ENCODING"].should == "deflate"
|
93
|
+
|
94
|
+
EventMachine.stop
|
95
|
+
}
|
96
|
+
}
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should stream chunked gzipped data" do
|
100
|
+
EventMachine.run {
|
101
|
+
options = {:head => {"accept-encoding" => "gzip"}}
|
102
|
+
# GitHub sends chunked gzip, time for a little Inception ;)
|
103
|
+
http = EventMachine::HttpRequest.new('https://github.com/igrigorik/em-http-request/commits/master').get options
|
104
|
+
|
105
|
+
http.errback { failed(http) }
|
106
|
+
http.callback {
|
107
|
+
http.response_header.status.should == 200
|
108
|
+
http.response_header["CONTENT_ENCODING"].should == "gzip"
|
109
|
+
http.response.should == ''
|
110
|
+
|
111
|
+
EventMachine.stop
|
112
|
+
}
|
113
|
+
|
114
|
+
body = ''
|
115
|
+
http.stream do |chunk|
|
116
|
+
body << chunk
|
117
|
+
end
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
121
|
+
context "keepalive" do
|
122
|
+
it "should default to non-keepalive" do
|
123
|
+
EventMachine.run {
|
124
|
+
headers = {'If-Modified-Since' => 'Thu, 05 Aug 2010 22:54:44 GMT'}
|
125
|
+
http = EventMachine::HttpRequest.new('http://www.google.com/images/logos/ps_logo2.png').get :head => headers
|
126
|
+
|
127
|
+
http.errback { fail }
|
128
|
+
start = Time.now.to_i
|
129
|
+
http.callback {
|
130
|
+
(Time.now.to_i - start).should be_within(2).of(0)
|
131
|
+
EventMachine.stop
|
132
|
+
}
|
133
|
+
}
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should work with keep-alive servers" do
|
137
|
+
EventMachine.run {
|
138
|
+
http = EventMachine::HttpRequest.new('http://mexicodiario.com/touch.public.json.php').get :keepalive => true
|
139
|
+
|
140
|
+
http.errback { failed(http) }
|
141
|
+
http.callback {
|
142
|
+
http.response_header.status.should == 200
|
143
|
+
EventMachine.stop
|
144
|
+
}
|
145
|
+
}
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
end
|
Binary file
|
data/spec/http_proxy_spec.rb
CHANGED
@@ -4,6 +4,7 @@ describe EventMachine::HttpRequest do
|
|
4
4
|
|
5
5
|
context "connections via" do
|
6
6
|
let(:proxy) { {:proxy => { :host => '127.0.0.1', :port => 8083 }} }
|
7
|
+
let(:authenticated_proxy) { {:proxy => { :host => '127.0.0.1', :port => 8083, :authorization => ["user", "name"] } } }
|
7
8
|
|
8
9
|
it "should use HTTP proxy" do
|
9
10
|
EventMachine.run {
|
@@ -12,6 +13,21 @@ describe EventMachine::HttpRequest do
|
|
12
13
|
http.errback { failed(http) }
|
13
14
|
http.callback {
|
14
15
|
http.response_header.status.should == 200
|
16
|
+
http.response_header.should_not include("X_PROXY_AUTH")
|
17
|
+
http.response.should match('test')
|
18
|
+
EventMachine.stop
|
19
|
+
}
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should use HTTP proxy with authentication" do
|
24
|
+
EventMachine.run {
|
25
|
+
http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/proxyauth?q=test', authenticated_proxy).get
|
26
|
+
|
27
|
+
http.errback { failed(http) }
|
28
|
+
http.callback {
|
29
|
+
http.response_header.status.should == 200
|
30
|
+
http.response_header['X_PROXY_AUTH'].should == "Proxy-Authorization: Basic dXNlcjpuYW1l"
|
15
31
|
http.response.should match('test')
|
16
32
|
EventMachine.stop
|
17
33
|
}
|
data/spec/pipelining_spec.rb
CHANGED
@@ -1,66 +1,66 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
requires_connection do
|
4
|
-
|
5
|
-
describe EventMachine::HttpRequest do
|
6
|
-
|
7
|
-
it "should perform successful pipelined GETs" do
|
8
|
-
EventMachine.run do
|
9
|
-
|
10
|
-
# Mongrel doesn't support pipelined requests - bah!
|
11
|
-
conn = EventMachine::HttpRequest.new('http://www.igvita.com/')
|
12
|
-
|
13
|
-
pipe1 = conn.get :keepalive => true
|
14
|
-
pipe2 = conn.get :path => '/archives/', :keepalive => true
|
15
|
-
|
16
|
-
processed = 0
|
17
|
-
stop = proc { EM.stop if processed == 2}
|
18
|
-
|
19
|
-
pipe1.errback { failed(conn) }
|
20
|
-
pipe1.callback {
|
21
|
-
processed += 1
|
22
|
-
pipe1.response_header.status.should == 200
|
23
|
-
stop.call
|
24
|
-
}
|
25
|
-
|
26
|
-
pipe2.errback { failed(conn) }
|
27
|
-
pipe2.callback {
|
28
|
-
processed += 1
|
29
|
-
pipe2.response_header.status.should == 200
|
30
|
-
pipe2.response.should match(/2011/i)
|
31
|
-
stop.call
|
32
|
-
}
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should perform successful pipelined HEAD requests" do
|
38
|
-
EventMachine.run do
|
39
|
-
conn = EventMachine::HttpRequest.new('http://www.igvita.com/')
|
40
|
-
|
41
|
-
pipe1 = conn.head :keepalive => true
|
42
|
-
pipe2 = conn.head :path => '/archives/', :keepalive => true
|
43
|
-
|
44
|
-
processed = 0
|
45
|
-
stop = proc { EM.stop if processed == 2}
|
46
|
-
|
47
|
-
pipe1.errback { failed(conn) }
|
48
|
-
pipe1.callback {
|
49
|
-
processed += 1
|
50
|
-
pipe1.response_header.status.should == 200
|
51
|
-
stop.call
|
52
|
-
}
|
53
|
-
|
54
|
-
pipe2.errback { failed(conn) }
|
55
|
-
pipe2.callback {
|
56
|
-
processed += 1
|
57
|
-
pipe2.response_header.status.should == 200
|
58
|
-
stop.call
|
59
|
-
}
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
requires_connection do
|
4
|
+
|
5
|
+
describe EventMachine::HttpRequest do
|
6
|
+
|
7
|
+
it "should perform successful pipelined GETs" do
|
8
|
+
EventMachine.run do
|
9
|
+
|
10
|
+
# Mongrel doesn't support pipelined requests - bah!
|
11
|
+
conn = EventMachine::HttpRequest.new('http://www.igvita.com/')
|
12
|
+
|
13
|
+
pipe1 = conn.get :keepalive => true
|
14
|
+
pipe2 = conn.get :path => '/archives/', :keepalive => true
|
15
|
+
|
16
|
+
processed = 0
|
17
|
+
stop = proc { EM.stop if processed == 2}
|
18
|
+
|
19
|
+
pipe1.errback { failed(conn) }
|
20
|
+
pipe1.callback {
|
21
|
+
processed += 1
|
22
|
+
pipe1.response_header.status.should == 200
|
23
|
+
stop.call
|
24
|
+
}
|
25
|
+
|
26
|
+
pipe2.errback { failed(conn) }
|
27
|
+
pipe2.callback {
|
28
|
+
processed += 1
|
29
|
+
pipe2.response_header.status.should == 200
|
30
|
+
pipe2.response.should match(/2011/i)
|
31
|
+
stop.call
|
32
|
+
}
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should perform successful pipelined HEAD requests" do
|
38
|
+
EventMachine.run do
|
39
|
+
conn = EventMachine::HttpRequest.new('http://www.igvita.com/')
|
40
|
+
|
41
|
+
pipe1 = conn.head :keepalive => true
|
42
|
+
pipe2 = conn.head :path => '/archives/', :keepalive => true
|
43
|
+
|
44
|
+
processed = 0
|
45
|
+
stop = proc { EM.stop if processed == 2}
|
46
|
+
|
47
|
+
pipe1.errback { failed(conn) }
|
48
|
+
pipe1.callback {
|
49
|
+
processed += 1
|
50
|
+
pipe1.response_header.status.should == 200
|
51
|
+
stop.call
|
52
|
+
}
|
53
|
+
|
54
|
+
pipe2.errback { failed(conn) }
|
55
|
+
pipe2.callback {
|
56
|
+
processed += 1
|
57
|
+
pipe2.response_header.status.should == 200
|
58
|
+
stop.call
|
59
|
+
}
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
66
|
end
|
data/spec/redirect_spec.rb
CHANGED
@@ -185,6 +185,21 @@ describe EventMachine::HttpRequest do
|
|
185
185
|
}
|
186
186
|
end
|
187
187
|
|
188
|
+
it "should apply timeout settings on redirects" do
|
189
|
+
EventMachine.run {
|
190
|
+
t = Time.now.to_i
|
191
|
+
EventMachine.heartbeat_interval = 0.1
|
192
|
+
|
193
|
+
conn = EventMachine::HttpRequest.new('http://127.0.0.1:8090/redirect/timeout', :inactivity_timeout => 0.1)
|
194
|
+
http = conn.get :redirects => 1
|
195
|
+
http.callback { failed(http) }
|
196
|
+
http.errback {
|
197
|
+
(Time.now.to_i - t).should <= 1
|
198
|
+
EM.stop
|
199
|
+
}
|
200
|
+
}
|
201
|
+
end
|
202
|
+
|
188
203
|
it "should capture and pass cookies on redirect and pass_cookies by default" do
|
189
204
|
EventMachine.run {
|
190
205
|
http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/redirect/multiple-with-cookie').get :redirects => 2, :head => {'cookie' => 'id=2;'}
|