em-http-request 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of em-http-request might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/em-http-request.gemspec +1 -1
- data/lib/em-http/client.rb +4 -5
- data/lib/em-http/http_client_options.rb +4 -4
- data/lib/em-http/http_connection.rb +41 -9
- data/lib/em-http/http_encoding.rb +5 -3
- data/lib/em-http/http_header.rb +5 -5
- data/lib/em-http/middleware/json_response.rb +1 -1
- data/lib/em-http/version.rb +1 -1
- data/spec/client_spec.rb +28 -1
- data/spec/external_spec.rb +3 -3
- data/spec/helper.rb +1 -0
- data/spec/pipelining_spec.rb +4 -4
- data/spec/redirect_spec.rb +65 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/stallion.rb +10 -2
- data/spec/stub_server.rb +6 -3
- metadata +32 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6b892384de4aaa4e5983ce807f416814c0f5768
|
4
|
+
data.tar.gz: e7a1f158af27740ba67b4515ae3e338dff44666d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44faab083fdc1c80147ec45999ad6fc8490bfde5ee6dd5b9a06969ef7b49918c08e3c6fbc1eb552f527cfd17fca78fdcad2fc30bf4a62bb0fa2027b266b4f48a
|
7
|
+
data.tar.gz: 74ee5fd141fb0055383e0befb7e7ed75c567273d445652187088c33dbe3a4d424ee0505b673953eb402248f066384e5c1b9ba2bc141b1b2560c67c441e9731f6
|
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
# EM-HTTP-Request
|
1
|
+
# EM-HTTP-Request
|
2
|
+
|
3
|
+
[](http://rubygems.org/gems/em-http-request)
|
4
|
+
[](https://github.com/igrigorik/ga-beacon)
|
2
5
|
|
3
6
|
Async (EventMachine) HTTP client, with support for:
|
4
7
|
|
@@ -54,7 +57,6 @@ Several higher-order Ruby projects have incorporated em-http and other Ruby HTTP
|
|
54
57
|
- [Firering](https://github.com/EmmanuelOga/firering) - Eventmachine powered Campfire API
|
55
58
|
- [RDaneel](https://github.com/hasmanydevelopers/RDaneel) - Ruby crawler which respects robots.txt
|
56
59
|
- [em-eventsource](https://github.com/AF83/em-eventsource) - EventSource client for EventMachine
|
57
|
-
- [sinatra-synchrony](https://github.com/kyledrake/sinatra-synchrony) - Sinatra plugin for synchronous use of EM
|
58
60
|
- and many others.. drop me a link if you want yours included!
|
59
61
|
|
60
62
|
### License
|
data/em-http-request.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.rubyforge_project = 'em-http-request'
|
17
17
|
|
18
18
|
s.add_dependency 'addressable', '>= 2.3.4'
|
19
|
-
s.add_dependency 'cookiejar'
|
19
|
+
s.add_dependency 'cookiejar', '<= 0.3.0'
|
20
20
|
s.add_dependency 'em-socksify', '>= 0.3'
|
21
21
|
s.add_dependency 'eventmachine', '>= 1.0.3'
|
22
22
|
s.add_dependency 'http_parser.rb', '>= 0.6.0'
|
data/lib/em-http/client.rb
CHANGED
@@ -21,7 +21,7 @@ module EventMachine
|
|
21
21
|
|
22
22
|
CRLF="\r\n"
|
23
23
|
|
24
|
-
attr_accessor :state, :response
|
24
|
+
attr_accessor :state, :response, :conn
|
25
25
|
attr_reader :response_header, :error, :content_charset, :req, :cookies
|
26
26
|
|
27
27
|
def initialize(conn, options)
|
@@ -100,14 +100,13 @@ module EventMachine
|
|
100
100
|
|
101
101
|
@cookies.clear
|
102
102
|
@cookies = @cookiejar.get(@response_header.location).map(&:to_s) if @req.pass_cookies
|
103
|
-
@req.set_uri(@response_header.location)
|
104
103
|
|
105
|
-
@conn.redirect(self)
|
104
|
+
@conn.redirect(self, @response_header.location)
|
106
105
|
else
|
107
106
|
succeed(self)
|
108
107
|
end
|
109
108
|
|
110
|
-
rescue
|
109
|
+
rescue => e
|
111
110
|
on_error(e.message)
|
112
111
|
end
|
113
112
|
else
|
@@ -189,7 +188,7 @@ module EventMachine
|
|
189
188
|
head['content-type'] = 'application/x-www-form-urlencoded'
|
190
189
|
end
|
191
190
|
|
192
|
-
request_header ||= encode_request(@req.method, @req.uri, query, @conn.connopts
|
191
|
+
request_header ||= encode_request(@req.method, @req.uri, query, @conn.connopts)
|
193
192
|
request_header << encode_headers(head)
|
194
193
|
request_header << CRLF
|
195
194
|
@conn.send_data request_header
|
@@ -12,8 +12,6 @@ class HttpClientOptions
|
|
12
12
|
|
13
13
|
@method = method.to_s.upcase
|
14
14
|
@headers = options[:head] || {}
|
15
|
-
@query = options[:query]
|
16
|
-
|
17
15
|
|
18
16
|
@file = options[:file]
|
19
17
|
@body = options[:body]
|
@@ -21,14 +19,14 @@ class HttpClientOptions
|
|
21
19
|
@pass_cookies = options.fetch(:pass_cookies, true) # pass cookies between redirects
|
22
20
|
@decoding = options.fetch(:decoding, true) # auto-decode compressed response
|
23
21
|
|
24
|
-
set_uri(uri, options[:path])
|
22
|
+
set_uri(uri, options[:path], options[:query])
|
25
23
|
end
|
26
24
|
|
27
25
|
def follow_redirect?; @followed < @redirects; end
|
28
26
|
def ssl?; @uri.scheme == "https" || @uri.port == 443; end
|
29
27
|
def no_body?; @method == "HEAD"; end
|
30
28
|
|
31
|
-
def set_uri(uri, path = nil)
|
29
|
+
def set_uri(uri, path = nil, query = nil)
|
32
30
|
uri = uri.kind_of?(Addressable::URI) ? uri : Addressable::URI::parse(uri.to_s)
|
33
31
|
uri.path = path if path
|
34
32
|
uri.path = '/' if uri.path.empty?
|
@@ -37,6 +35,7 @@ class HttpClientOptions
|
|
37
35
|
@path = uri.path
|
38
36
|
@host = uri.host
|
39
37
|
@port = uri.port
|
38
|
+
@query = query
|
40
39
|
|
41
40
|
# Make sure the ports are set as Addressable::URI doesn't
|
42
41
|
# set the port if it isn't there
|
@@ -44,5 +43,6 @@ class HttpClientOptions
|
|
44
43
|
@port = @uri.scheme == "https" ? 443 : 80
|
45
44
|
end
|
46
45
|
|
46
|
+
uri
|
47
47
|
end
|
48
48
|
end
|
@@ -37,8 +37,8 @@ module EventMachine
|
|
37
37
|
include Socksify
|
38
38
|
include Connectify
|
39
39
|
|
40
|
-
attr_reader :deferred
|
41
|
-
attr_accessor :error, :connopts, :uri
|
40
|
+
attr_reader :deferred, :conn
|
41
|
+
attr_accessor :error, :connopts, :uri
|
42
42
|
|
43
43
|
def initialize
|
44
44
|
@deferred = true
|
@@ -97,7 +97,7 @@ module EventMachine
|
|
97
97
|
@conn.callback { c.connection_completed }
|
98
98
|
|
99
99
|
middleware.each do |m|
|
100
|
-
c.callback
|
100
|
+
c.callback(&m.method(:response)) if m.respond_to?(:response)
|
101
101
|
end
|
102
102
|
|
103
103
|
@clients.push c
|
@@ -114,8 +114,16 @@ module EventMachine
|
|
114
114
|
@p = Http::Parser.new
|
115
115
|
@p.header_value_type = :mixed
|
116
116
|
@p.on_headers_complete = proc do |h|
|
117
|
-
client
|
118
|
-
|
117
|
+
if client
|
118
|
+
client.parse_response_header(h, @p.http_version, @p.status_code)
|
119
|
+
:reset if client.req.no_body?
|
120
|
+
else
|
121
|
+
# if we receive unexpected data without a pending client request
|
122
|
+
# reset the parser to avoid firing any further callbacks and close
|
123
|
+
# the connection because we're processing invalid HTTP
|
124
|
+
@p.reset!
|
125
|
+
unbind
|
126
|
+
end
|
119
127
|
end
|
120
128
|
|
121
129
|
@p.on_body = proc do |b|
|
@@ -152,9 +160,9 @@ module EventMachine
|
|
152
160
|
@peer = @conn.get_peername
|
153
161
|
|
154
162
|
if @connopts.socks_proxy?
|
155
|
-
socksify(client.req.uri.host, client.req.uri.
|
163
|
+
socksify(client.req.uri.host, client.req.uri.inferred_port, *@connopts.proxy[:authorization]) { start }
|
156
164
|
elsif @connopts.connect_proxy?
|
157
|
-
connectify(client.req.uri.host, client.req.uri.
|
165
|
+
connectify(client.req.uri.host, client.req.uri.inferred_port, *@connopts.proxy[:authorization]) { start }
|
158
166
|
else
|
159
167
|
start
|
160
168
|
end
|
@@ -165,8 +173,32 @@ module EventMachine
|
|
165
173
|
@conn.succeed
|
166
174
|
end
|
167
175
|
|
168
|
-
def redirect(client)
|
169
|
-
|
176
|
+
def redirect(client, new_location)
|
177
|
+
old_location = client.req.uri
|
178
|
+
new_location = client.req.set_uri(new_location)
|
179
|
+
|
180
|
+
if client.req.keepalive
|
181
|
+
# Application requested a keep-alive connection but one of the requests
|
182
|
+
# hits a cross-origin redirect. We need to open a new connection and
|
183
|
+
# let both connections proceed simultaneously.
|
184
|
+
if old_location.origin != new_location.origin
|
185
|
+
conn = HttpConnection.new
|
186
|
+
client.conn = conn
|
187
|
+
conn.connopts = @connopts
|
188
|
+
conn.uri = client.req.uri
|
189
|
+
conn.activate_connection(client)
|
190
|
+
|
191
|
+
# If the redirect is a same-origin redirect on a keep-alive request
|
192
|
+
# then immidiately dispatch the request over existing connection.
|
193
|
+
else
|
194
|
+
@clients.push client
|
195
|
+
client.connection_completed
|
196
|
+
end
|
197
|
+
else
|
198
|
+
# If connection is not keep-alive the unbind will fire and we'll
|
199
|
+
# reconnect using the same connection object.
|
200
|
+
@pending.push client
|
201
|
+
end
|
170
202
|
end
|
171
203
|
|
172
204
|
def unbind(reason = nil)
|
@@ -46,12 +46,14 @@ module EventMachine
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
def encode_request(method, uri, query,
|
49
|
+
def encode_request(method, uri, query, connopts)
|
50
50
|
query = encode_query(uri, query)
|
51
51
|
|
52
52
|
# Non CONNECT proxies require that you provide the full request
|
53
53
|
# uri in request header, as opposed to a relative path.
|
54
|
-
|
54
|
+
# Don't modify the header with CONNECT proxies. It's unneeded and will
|
55
|
+
# cause 400 Bad Request errors with many standard setups.
|
56
|
+
query = uri.join(query) if connopts.proxy && !connopts.connect_proxy?
|
55
57
|
|
56
58
|
HTTP_REQUEST_HEADER % [method.to_s.upcase, query]
|
57
59
|
end
|
@@ -112,7 +114,7 @@ module EventMachine
|
|
112
114
|
# String - custom auth string (OAuth, etc)
|
113
115
|
def encode_auth(k,v)
|
114
116
|
if v.is_a? Array
|
115
|
-
FIELD_ENCODING % [k, ["Basic", Base64.
|
117
|
+
FIELD_ENCODING % [k, ["Basic", Base64.strict_encode64(v.join(":")).split.join].join(" ")]
|
116
118
|
else
|
117
119
|
encode_field(k,v)
|
118
120
|
end
|
data/lib/em-http/http_header.rb
CHANGED
@@ -2,13 +2,13 @@ module EventMachine
|
|
2
2
|
# A simple hash is returned for each request made by HttpClient with the
|
3
3
|
# headers that were given by the server for that request.
|
4
4
|
class HttpResponseHeader < Hash
|
5
|
-
# The reason returned in the http response ("OK"
|
5
|
+
# The reason returned in the http response (string - e.g. "OK")
|
6
6
|
attr_accessor :http_reason
|
7
7
|
|
8
|
-
# The HTTP version returned.
|
8
|
+
# The HTTP version returned (string - e.g. "1.1")
|
9
9
|
attr_accessor :http_version
|
10
10
|
|
11
|
-
# The status code (
|
11
|
+
# The status code (integer - e.g. 200)
|
12
12
|
attr_accessor :http_status
|
13
13
|
|
14
14
|
# Raw headers
|
@@ -23,9 +23,9 @@ module EventMachine
|
|
23
23
|
self[HttpClient::LAST_MODIFIED]
|
24
24
|
end
|
25
25
|
|
26
|
-
# HTTP response status
|
26
|
+
# HTTP response status
|
27
27
|
def status
|
28
|
-
|
28
|
+
Integer(http_status) rescue 0
|
29
29
|
end
|
30
30
|
|
31
31
|
# Length of content as an integer, or nil if chunked/unspecified
|
data/lib/em-http/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -51,7 +51,7 @@ describe EventMachine::HttpRequest do
|
|
51
51
|
EventMachine.run {
|
52
52
|
lambda {
|
53
53
|
EventMachine::HttpRequest.new('random?text').get
|
54
|
-
}.should raise_error
|
54
|
+
}.should raise_error(Addressable::URI::InvalidURIError)
|
55
55
|
|
56
56
|
EM.stop
|
57
57
|
}
|
@@ -848,6 +848,33 @@ describe EventMachine::HttpRequest do
|
|
848
848
|
}
|
849
849
|
end
|
850
850
|
|
851
|
+
it "should close connection on invalid HTTP response" do
|
852
|
+
EventMachine.run {
|
853
|
+
response =<<-HTTP.gsub(/^ +/, '').strip
|
854
|
+
HTTP/1.1 403 Forbidden
|
855
|
+
Content-Type: text/plain
|
856
|
+
Content-Length: 13
|
857
|
+
|
858
|
+
Access Denied
|
859
|
+
|
860
|
+
HTTP/1.1 403 Forbidden
|
861
|
+
Content-Type: text/plain
|
862
|
+
Content-Length: 13
|
863
|
+
|
864
|
+
Access Denied
|
865
|
+
HTTP
|
866
|
+
|
867
|
+
@s = StubServer.new(response)
|
868
|
+
lambda {
|
869
|
+
conn = EventMachine::HttpRequest.new('http://127.0.0.1:8081/')
|
870
|
+
req = conn.get
|
871
|
+
req.errback { failed(http) }
|
872
|
+
req.callback { EM.stop }
|
873
|
+
}.should_not raise_error
|
874
|
+
|
875
|
+
}
|
876
|
+
end
|
877
|
+
|
851
878
|
context "User-Agent" do
|
852
879
|
it 'should default to "EventMachine HttpClient"' do
|
853
880
|
EventMachine.run {
|
data/spec/external_spec.rb
CHANGED
@@ -80,11 +80,11 @@ requires_connection do
|
|
80
80
|
end
|
81
81
|
|
82
82
|
it "should detect deflate encoding" do
|
83
|
-
pending "need an endpoint which supports deflate.. MSN is no longer"
|
83
|
+
# pending "need an endpoint which supports deflate.. MSN is no longer"
|
84
84
|
EventMachine.run {
|
85
85
|
|
86
86
|
options = {:head => {"accept-encoding" => "deflate"}, :redirects => 5}
|
87
|
-
http = EventMachine::HttpRequest.new('http://www.
|
87
|
+
http = EventMachine::HttpRequest.new('http://www.libpng.org/').get options
|
88
88
|
|
89
89
|
http.errback { failed(http) }
|
90
90
|
http.callback {
|
@@ -135,7 +135,7 @@ requires_connection do
|
|
135
135
|
|
136
136
|
it "should work with keep-alive servers" do
|
137
137
|
EventMachine.run {
|
138
|
-
http = EventMachine::HttpRequest.new('
|
138
|
+
http = EventMachine::HttpRequest.new('https://github.com/igrigorik/em-http-request').get :keepalive => true
|
139
139
|
|
140
140
|
http.errback { failed(http) }
|
141
141
|
http.callback {
|
data/spec/helper.rb
CHANGED
data/spec/pipelining_spec.rb
CHANGED
@@ -8,10 +8,10 @@ requires_connection do
|
|
8
8
|
EventMachine.run do
|
9
9
|
|
10
10
|
# Mongrel doesn't support pipelined requests - bah!
|
11
|
-
conn = EventMachine::HttpRequest.new('http://www.
|
11
|
+
conn = EventMachine::HttpRequest.new('http://www.mexicodiario.com/')
|
12
12
|
|
13
13
|
pipe1 = conn.get :keepalive => true
|
14
|
-
pipe2 = conn.get :path => '/
|
14
|
+
pipe2 = conn.get :path => '/contact/', :keepalive => true
|
15
15
|
|
16
16
|
processed = 0
|
17
17
|
stop = proc { EM.stop if processed == 2}
|
@@ -36,10 +36,10 @@ requires_connection do
|
|
36
36
|
|
37
37
|
it "should perform successful pipelined HEAD requests" do
|
38
38
|
EventMachine.run do
|
39
|
-
conn = EventMachine::HttpRequest.new('http://www.
|
39
|
+
conn = EventMachine::HttpRequest.new('http://www.mexicodiario.com/')
|
40
40
|
|
41
41
|
pipe1 = conn.head :keepalive => true
|
42
|
-
pipe2 = conn.head :path => '/
|
42
|
+
pipe2 = conn.head :path => '/contact/', :keepalive => true
|
43
43
|
|
44
44
|
processed = 0
|
45
45
|
stop = proc { EM.stop if processed == 2}
|
data/spec/redirect_spec.rb
CHANGED
@@ -362,4 +362,69 @@ describe EventMachine::HttpRequest do
|
|
362
362
|
}
|
363
363
|
end
|
364
364
|
|
365
|
+
it "should ignore query option when redirecting" do
|
366
|
+
EventMachine.run {
|
367
|
+
http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/redirect/ignore_query_option').get :redirects => 1, :query => 'ignore=1'
|
368
|
+
http.errback { failed(http) }
|
369
|
+
http.callback {
|
370
|
+
http.last_effective_url.to_s.should == 'http://127.0.0.1:8090/redirect/url'
|
371
|
+
http.redirects.should == 1
|
372
|
+
|
373
|
+
redirect_url = http.response
|
374
|
+
redirect_url.should == http.last_effective_url.to_s
|
375
|
+
|
376
|
+
EM.stop
|
377
|
+
}
|
378
|
+
}
|
379
|
+
end
|
380
|
+
|
381
|
+
it "should work with keep-alive connections with cross-origin redirect" do
|
382
|
+
Timeout.timeout(1) {
|
383
|
+
EventMachine.run {
|
384
|
+
response =<<-HTTP.gsub(/^ +/, '')
|
385
|
+
HTTP/1.1 301 MOVED PERMANENTLY
|
386
|
+
Location: http://127.0.0.1:8090/
|
387
|
+
Content-Length: 0
|
388
|
+
|
389
|
+
HTTP
|
390
|
+
|
391
|
+
stub_server = StubServer.new(:host => '127.0.0.1', :port => 8070, :keepalive => true, :response => response)
|
392
|
+
conn = EventMachine::HttpRequest.new('http://127.0.0.1:8070/', :inactivity_timeout => 60)
|
393
|
+
http = conn.get :redirects => 1, :keepalive => true
|
394
|
+
http.errback { failed(http) }
|
395
|
+
http.callback {
|
396
|
+
http.last_effective_url.to_s.should == 'http://127.0.0.1:8090/'
|
397
|
+
http.redirects.should == 1
|
398
|
+
|
399
|
+
stub_server.stop
|
400
|
+
EM.stop
|
401
|
+
}
|
402
|
+
}
|
403
|
+
}
|
404
|
+
end
|
405
|
+
|
406
|
+
it "should work with keep-alive connections with same-origin redirect" do
|
407
|
+
Timeout.timeout(1) {
|
408
|
+
EventMachine.run {
|
409
|
+
response =<<-HTTP.gsub(/^ +/, '')
|
410
|
+
HTTP/1.1 301 MOVED PERMANENTLY
|
411
|
+
Location: http://127.0.0.1:8070/
|
412
|
+
Content-Length: 0
|
413
|
+
|
414
|
+
HTTP
|
415
|
+
|
416
|
+
stub_server = StubServer.new(:host => '127.0.0.1', :port => 8070, :keepalive => true, :response => response)
|
417
|
+
conn = EventMachine::HttpRequest.new('http://127.0.0.1:8070/', :inactivity_timeout => 60)
|
418
|
+
http = conn.get :redirects => 1, :keepalive => true
|
419
|
+
http.errback { failed(http) }
|
420
|
+
http.callback {
|
421
|
+
http.last_effective_url.to_s.should == 'http://127.0.0.1:8070/'
|
422
|
+
http.redirects.should == 1
|
423
|
+
|
424
|
+
stub_server.stop
|
425
|
+
EM.stop
|
426
|
+
}
|
427
|
+
}
|
428
|
+
}
|
429
|
+
end
|
365
430
|
end
|
data/spec/spec_helper.rb
ADDED
data/spec/stallion.rb
CHANGED
@@ -201,6 +201,14 @@ Stallion.saddle :spec do |stable|
|
|
201
201
|
stable.response.status = 301
|
202
202
|
stable.response["Location"] = "https://host:443/"
|
203
203
|
|
204
|
+
elsif stable.request.path_info == '/redirect/ignore_query_option'
|
205
|
+
stable.response.status = 301
|
206
|
+
stable.response['Location'] = '/redirect/url'
|
207
|
+
|
208
|
+
elsif stable.request.path_info == '/redirect/url'
|
209
|
+
stable.response.status = 200
|
210
|
+
stable.response.write stable.request.url
|
211
|
+
|
204
212
|
elsif stable.request.path_info == '/gzip'
|
205
213
|
io = StringIO.new
|
206
214
|
gzip = Zlib::GzipWriter.new(io)
|
@@ -234,7 +242,7 @@ Stallion.saddle :spec do |stable|
|
|
234
242
|
stable.response.status = 200
|
235
243
|
stable.response.write stable.request.env["HTTP_AUTHORIZATION"]
|
236
244
|
elsif stable.request.path_info == '/authtest'
|
237
|
-
auth = "Basic %s" % Base64.
|
245
|
+
auth = "Basic %s" % Base64.strict_encode64(['user', 'pass'].join(':')).split.join
|
238
246
|
if auth == stable.request.env["HTTP_AUTHORIZATION"]
|
239
247
|
stable.response.status = 200
|
240
248
|
stable.response.write 'success'
|
@@ -257,7 +265,7 @@ end
|
|
257
265
|
Thread.new do
|
258
266
|
begin
|
259
267
|
Stallion.run :Host => '127.0.0.1', :Port => 8090
|
260
|
-
rescue
|
268
|
+
rescue => e
|
261
269
|
print e
|
262
270
|
end
|
263
271
|
end
|
data/spec/stub_server.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
class StubServer
|
2
2
|
module Server
|
3
|
+
attr_accessor :keepalive
|
4
|
+
|
3
5
|
def receive_data(data)
|
4
6
|
if echo?
|
5
7
|
send_data("HTTP/1.0 200 OK\r\nContent-Length: #{data.bytesize}\r\nContent-Type: text/plain\r\n\r\n")
|
@@ -8,7 +10,7 @@ class StubServer
|
|
8
10
|
send_data @response
|
9
11
|
end
|
10
12
|
|
11
|
-
close_connection_after_writing
|
13
|
+
close_connection_after_writing unless keepalive
|
12
14
|
end
|
13
15
|
|
14
16
|
def echo= flag
|
@@ -31,8 +33,9 @@ class StubServer
|
|
31
33
|
host = options[:host]
|
32
34
|
port = options[:port]
|
33
35
|
@sig = EventMachine::start_server(host, port, Server) do |server|
|
34
|
-
server.response
|
35
|
-
server.echo
|
36
|
+
server.response = options[:response]
|
37
|
+
server.echo = options[:echo]
|
38
|
+
server.keepalive = options[:keepalive]
|
36
39
|
end
|
37
40
|
end
|
38
41
|
|
metadata
CHANGED
@@ -1,153 +1,153 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-http-request
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Grigorik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 2.3.4
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.3.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: cookiejar
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - "<="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.3.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - "<="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.3.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: em-socksify
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0.3'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: eventmachine
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 1.0.3
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 1.0.3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: http_parser.rb
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 0.6.0
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.6.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: mongrel
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - ~>
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: 1.2.0.pre2
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - ~>
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 1.2.0.pre2
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: multi_json
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rack
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rake
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: rspec
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- -
|
143
|
+
- - ">="
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: '0'
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- -
|
150
|
+
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
description: EventMachine based, async HTTP Request client
|
@@ -157,9 +157,9 @@ executables: []
|
|
157
157
|
extensions: []
|
158
158
|
extra_rdoc_files: []
|
159
159
|
files:
|
160
|
-
- .gemtest
|
161
|
-
- .gitignore
|
162
|
-
- .rspec
|
160
|
+
- ".gemtest"
|
161
|
+
- ".gitignore"
|
162
|
+
- ".rspec"
|
163
163
|
- Changelog.md
|
164
164
|
- Gemfile
|
165
165
|
- README.md
|
@@ -213,6 +213,7 @@ files:
|
|
213
213
|
- spec/pipelining_spec.rb
|
214
214
|
- spec/redirect_spec.rb
|
215
215
|
- spec/socksify_proxy_spec.rb
|
216
|
+
- spec/spec_helper.rb
|
216
217
|
- spec/ssl_spec.rb
|
217
218
|
- spec/stallion.rb
|
218
219
|
- spec/stub_server.rb
|
@@ -226,17 +227,17 @@ require_paths:
|
|
226
227
|
- lib
|
227
228
|
required_ruby_version: !ruby/object:Gem::Requirement
|
228
229
|
requirements:
|
229
|
-
- -
|
230
|
+
- - ">="
|
230
231
|
- !ruby/object:Gem::Version
|
231
232
|
version: '0'
|
232
233
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
233
234
|
requirements:
|
234
|
-
- -
|
235
|
+
- - ">="
|
235
236
|
- !ruby/object:Gem::Version
|
236
237
|
version: '0'
|
237
238
|
requirements: []
|
238
239
|
rubyforge_project: em-http-request
|
239
|
-
rubygems_version: 2.
|
240
|
+
rubygems_version: 2.4.5.1
|
240
241
|
signing_key:
|
241
242
|
specification_version: 4
|
242
243
|
summary: EventMachine based, async HTTP Request client
|
@@ -258,6 +259,7 @@ test_files:
|
|
258
259
|
- spec/pipelining_spec.rb
|
259
260
|
- spec/redirect_spec.rb
|
260
261
|
- spec/socksify_proxy_spec.rb
|
262
|
+
- spec/spec_helper.rb
|
261
263
|
- spec/ssl_spec.rb
|
262
264
|
- spec/stallion.rb
|
263
265
|
- spec/stub_server.rb
|