em-http-request 1.1.1 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,8 +37,8 @@ describe EventMachine::MultiRequest do
37
37
 
38
38
  describe "#requests" do
39
39
  it "should return the added requests" do
40
- request1 = stub('request1', :callback => nil, :errback => nil)
41
- request2 = stub('request2', :callback => nil, :errback => nil)
40
+ request1 = double('request1', :callback => nil, :errback => nil)
41
+ request2 = double('request2', :callback => nil, :errback => nil)
42
42
 
43
43
  multi.add :a, request1
44
44
  multi.add :b, request2
@@ -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.igvita.com/')
11
+ conn = EventMachine::HttpRequest.new('http://www.bing.com/')
12
12
 
13
13
  pipe1 = conn.get :keepalive => true
14
- pipe2 = conn.get :path => '/archives/', :keepalive => true
14
+ pipe2 = conn.get :path => '/news', :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.igvita.com/')
39
+ conn = EventMachine::HttpRequest.new('http://www.bing.com/')
40
40
 
41
41
  pipe1 = conn.head :keepalive => true
42
- pipe2 = conn.head :path => '/archives/', :keepalive => true
42
+ pipe2 = conn.head :path => '/news', :keepalive => true
43
43
 
44
44
  processed = 0
45
45
  stop = proc { EM.stop if processed == 2}
@@ -318,4 +318,113 @@ describe EventMachine::HttpRequest do
318
318
  }
319
319
  end
320
320
 
321
+ it "should not add default http port to redirect url that don't include it" do
322
+ EventMachine.run {
323
+ conn = EventMachine::HttpRequest.new('http://127.0.0.1:8090/redirect/http_no_port')
324
+ http = conn.get :redirects => 1
325
+ http.errback {
326
+ http.last_effective_url.to_s.should == 'http://host/'
327
+ EM.stop
328
+ }
329
+ }
330
+ end
331
+
332
+ it "should not add default https port to redirect url that don't include it" do
333
+ EventMachine.run {
334
+ conn = EventMachine::HttpRequest.new('http://127.0.0.1:8090/redirect/https_no_port')
335
+ http = conn.get :redirects => 1
336
+ http.errback {
337
+ http.last_effective_url.to_s.should == 'https://host/'
338
+ EM.stop
339
+ }
340
+ }
341
+ end
342
+
343
+ it "should keep default http port in redirect url that include it" do
344
+ EventMachine.run {
345
+ conn = EventMachine::HttpRequest.new('http://127.0.0.1:8090/redirect/http_with_port')
346
+ http = conn.get :redirects => 1
347
+ http.errback {
348
+ http.last_effective_url.to_s.should == 'http://host:80/'
349
+ EM.stop
350
+ }
351
+ }
352
+ end
353
+
354
+ it "should keep default https port in redirect url that include it" do
355
+ EventMachine.run {
356
+ conn = EventMachine::HttpRequest.new('http://127.0.0.1:8090/redirect/https_with_port')
357
+ http = conn.get :redirects => 1
358
+ http.errback {
359
+ http.last_effective_url.to_s.should == 'https://host:443/'
360
+ EM.stop
361
+ }
362
+ }
363
+ end
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
321
430
  end
@@ -0,0 +1,25 @@
1
+ PROXY_ENV_VARS = %w[HTTP_PROXY http_proxy HTTPS_PROXY https_proxy ALL_PROXY]
2
+
3
+ RSpec.configure do |config|
4
+ proxy_envs = {}
5
+
6
+ config.mock_with :rspec do |c|
7
+ c.syntax = [:should, :expect]
8
+ end
9
+ config.expect_with :rspec do |c|
10
+ c.syntax = [:should, :expect]
11
+ end
12
+
13
+ config.before :all do
14
+ # Back-up ENV *_PROXY vars
15
+ orig_proxy_envs = Hash[
16
+ PROXY_ENV_VARS.select {|k| ENV.key? k }.map {|k| [k, ENV.delete(k)] }
17
+ ]
18
+ proxy_envs.replace(orig_proxy_envs)
19
+ end
20
+
21
+ config.after :all do
22
+ # Restore ENV *_PROXY vars
23
+ ENV.update(proxy_envs)
24
+ end
25
+ end
@@ -1,6 +1,6 @@
1
1
  # #--
2
2
  # Includes portion originally Copyright (C)2008 Michael Fellinger
3
- # license See file LICENSE for details
3
+ # MIT License
4
4
  # #--
5
5
 
6
6
  require 'rack'
@@ -17,7 +17,7 @@ module Stallion
17
17
 
18
18
  def match?(request)
19
19
  method = request['REQUEST_METHOD']
20
- right_method = @methods.empty? or @methods.include?(method)
20
+ @methods.empty? or @methods.include?(method)
21
21
  end
22
22
  end
23
23
 
@@ -36,7 +36,7 @@ module Stallion
36
36
 
37
37
  def call(request, response)
38
38
  @request, @response = request, response
39
- @boxes.each do |(path, methods), mount|
39
+ @boxes.each do |_, mount|
40
40
  if mount.match?(request)
41
41
  mount.ride
42
42
  end
@@ -96,6 +96,9 @@ Stallion.saddle :spec do |stable|
96
96
  elsif stable.request.path_info == '/echo_content_length_from_header'
97
97
  stable.response.write "content-length:#{stable.request.env["CONTENT_LENGTH"]}"
98
98
 
99
+ elsif stable.request.path_info == '/echo_authorization_header'
100
+ stable.response.write "authorization:#{stable.request.env["HTTP_AUTHORIZATION"]}"
101
+
99
102
  elsif stable.request.head? && stable.request.path_info == '/'
100
103
  stable.response.status = 200
101
104
 
@@ -185,6 +188,30 @@ Stallion.saddle :spec do |stable|
185
188
  stable.response.status = 301
186
189
  stable.response["Location"] = "http://$$$@$!%&^"
187
190
 
191
+ elsif stable.request.path_info == '/redirect/http_no_port'
192
+ stable.response.status = 301
193
+ stable.response["Location"] = "http://host/"
194
+
195
+ elsif stable.request.path_info == '/redirect/https_no_port'
196
+ stable.response.status = 301
197
+ stable.response["Location"] = "https://host/"
198
+
199
+ elsif stable.request.path_info == '/redirect/http_with_port'
200
+ stable.response.status = 301
201
+ stable.response["Location"] = "http://host:80/"
202
+
203
+ elsif stable.request.path_info == '/redirect/https_with_port'
204
+ stable.response.status = 301
205
+ stable.response["Location"] = "https://host:443/"
206
+
207
+ elsif stable.request.path_info == '/redirect/ignore_query_option'
208
+ stable.response.status = 301
209
+ stable.response['Location'] = '/redirect/url'
210
+
211
+ elsif stable.request.path_info == '/redirect/url'
212
+ stable.response.status = 200
213
+ stable.response.write stable.request.url
214
+
188
215
  elsif stable.request.path_info == '/gzip'
189
216
  io = StringIO.new
190
217
  gzip = Zlib::GzipWriter.new(io)
@@ -211,6 +238,10 @@ Stallion.saddle :spec do |stable|
211
238
  stable.response.write deflater.finish
212
239
  stable.response["Content-Encoding"] = "deflate"
213
240
 
241
+ elsif stable.request.path_info == '/echo_accept_encoding'
242
+ stable.response.status = 200
243
+ stable.response.write stable.request.env["HTTP_ACCEPT_ENCODING"]
244
+
214
245
  elsif stable.request.env["HTTP_IF_NONE_MATCH"]
215
246
  stable.response.status = 304
216
247
 
@@ -218,7 +249,7 @@ Stallion.saddle :spec do |stable|
218
249
  stable.response.status = 200
219
250
  stable.response.write stable.request.env["HTTP_AUTHORIZATION"]
220
251
  elsif stable.request.path_info == '/authtest'
221
- auth = "Basic %s" % Base64.encode64(['user', 'pass'].join(':')).split.join
252
+ auth = "Basic %s" % Base64.strict_encode64(['user', 'pass'].join(':')).split.join
222
253
  if auth == stable.request.env["HTTP_AUTHORIZATION"]
223
254
  stable.response.status = 200
224
255
  stable.response.write 'success'
@@ -241,7 +272,7 @@ end
241
272
  Thread.new do
242
273
  begin
243
274
  Stallion.run :Host => '127.0.0.1', :Port => 8090
244
- rescue Exception => e
275
+ rescue => e
245
276
  print e
246
277
  end
247
278
  end
@@ -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 = options[:response]
35
- server.echo = options[: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.1
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Grigorik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-24 00:00:00.000000000 Z
11
+ date: 2020-06-01 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: '0'
33
+ version: 0.3.1
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: '0'
40
+ version: 0.3.1
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
- version: 0.6.0.beta.2
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
- version: 0.6.0.beta.2
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
- version: '0'
117
+ version: '2.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
- version: '0'
124
+ version: '2.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,10 @@ 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
+ - ".travis.yml"
163
164
  - Changelog.md
164
165
  - Gemfile
165
166
  - README.md
@@ -196,6 +197,7 @@ files:
196
197
  - lib/em-http/multi.rb
197
198
  - lib/em-http/request.rb
198
199
  - lib/em-http/version.rb
200
+ - lib/em/io_streamer.rb
199
201
  - spec/client_fiber_spec.rb
200
202
  - spec/client_spec.rb
201
203
  - spec/digest_auth_spec.rb
@@ -213,11 +215,13 @@ files:
213
215
  - spec/pipelining_spec.rb
214
216
  - spec/redirect_spec.rb
215
217
  - spec/socksify_proxy_spec.rb
218
+ - spec/spec_helper.rb
216
219
  - spec/ssl_spec.rb
217
220
  - spec/stallion.rb
218
221
  - spec/stub_server.rb
219
222
  homepage: http://github.com/igrigorik/em-http-request
220
- licenses: []
223
+ licenses:
224
+ - MIT
221
225
  metadata: {}
222
226
  post_install_message:
223
227
  rdoc_options: []
@@ -225,17 +229,16 @@ require_paths:
225
229
  - lib
226
230
  required_ruby_version: !ruby/object:Gem::Requirement
227
231
  requirements:
228
- - - '>='
232
+ - - ">="
229
233
  - !ruby/object:Gem::Version
230
234
  version: '0'
231
235
  required_rubygems_version: !ruby/object:Gem::Requirement
232
236
  requirements:
233
- - - '>='
237
+ - - ">="
234
238
  - !ruby/object:Gem::Version
235
239
  version: '0'
236
240
  requirements: []
237
- rubyforge_project: em-http-request
238
- rubygems_version: 2.0.6
241
+ rubygems_version: 3.1.3
239
242
  signing_key:
240
243
  specification_version: 4
241
244
  summary: EventMachine based, async HTTP Request client
@@ -257,7 +260,7 @@ test_files:
257
260
  - spec/pipelining_spec.rb
258
261
  - spec/redirect_spec.rb
259
262
  - spec/socksify_proxy_spec.rb
263
+ - spec/spec_helper.rb
260
264
  - spec/ssl_spec.rb
261
265
  - spec/stallion.rb
262
266
  - spec/stub_server.rb
263
- has_rdoc: