em-http-request 1.1.2 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -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}
@@ -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
@@ -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
@@ -3,7 +3,6 @@ require 'helper'
3
3
  requires_connection do
4
4
 
5
5
  describe EventMachine::HttpRequest do
6
-
7
6
  it "should initiate SSL/TLS on HTTPS connections" do
8
7
  EventMachine.run {
9
8
  http = EventMachine::HttpRequest.new('https://mail.google.com:443/mail/').get
@@ -15,6 +14,58 @@ requires_connection do
15
14
  }
16
15
  }
17
16
  end
17
+
18
+ describe "TLS hostname verification" do
19
+ before do
20
+ @cve_warning = "[WARNING; em-http-request] TLS hostname validation is disabled (use 'tls: {verify_peer: true}'), see" +
21
+ " CVE-2020-13482 and https://github.com/igrigorik/em-http-request/issues/339 for details"
22
+ @orig_stderr = $stderr
23
+ $stderr = StringIO.new
24
+ end
25
+
26
+ after do
27
+ $stderr = @orig_stderr
28
+ end
29
+
30
+ it "should not warn if verify_peer is specified" do
31
+ EventMachine.run {
32
+ http = EventMachine::HttpRequest.new('https://mail.google.com:443/mail', {tls: {verify_peer: false}}).get
33
+
34
+ http.callback {
35
+ $stderr.rewind
36
+ $stderr.string.chomp.should_not eq(@cve_warning)
37
+
38
+ EventMachine.stop
39
+ }
40
+ }
41
+ end
42
+
43
+ it "should not warn if verify_peer is true" do
44
+ EventMachine.run {
45
+ http = EventMachine::HttpRequest.new('https://mail.google.com:443/mail', {tls: {verify_peer: true}}).get
46
+
47
+ http.callback {
48
+ $stderr.rewind
49
+ $stderr.string.chomp.should_not eq(@cve_warning)
50
+
51
+ EventMachine.stop
52
+ }
53
+ }
54
+ end
55
+
56
+ it "should warn if verify_peer is unspecified" do
57
+ EventMachine.run {
58
+ http = EventMachine::HttpRequest.new('https://mail.google.com:443/mail').get
59
+
60
+ http.callback {
61
+ $stderr.rewind
62
+ $stderr.string.chomp.should eq(@cve_warning)
63
+
64
+ EventMachine.stop
65
+ }
66
+ }
67
+ end
68
+ end
18
69
  end
19
70
 
20
71
  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
 
@@ -201,6 +204,14 @@ Stallion.saddle :spec do |stable|
201
204
  stable.response.status = 301
202
205
  stable.response["Location"] = "https://host:443/"
203
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
+
204
215
  elsif stable.request.path_info == '/gzip'
205
216
  io = StringIO.new
206
217
  gzip = Zlib::GzipWriter.new(io)
@@ -227,6 +238,10 @@ Stallion.saddle :spec do |stable|
227
238
  stable.response.write deflater.finish
228
239
  stable.response["Content-Encoding"] = "deflate"
229
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
+
230
245
  elsif stable.request.env["HTTP_IF_NONE_MATCH"]
231
246
  stable.response.status = 304
232
247
 
@@ -234,7 +249,7 @@ Stallion.saddle :spec do |stable|
234
249
  stable.response.status = 200
235
250
  stable.response.write stable.request.env["HTTP_AUTHORIZATION"]
236
251
  elsif stable.request.path_info == '/authtest'
237
- auth = "Basic %s" % Base64.encode64(['user', 'pass'].join(':')).split.join
252
+ auth = "Basic %s" % Base64.strict_encode64(['user', 'pass'].join(':')).split.join
238
253
  if auth == stable.request.env["HTTP_AUTHORIZATION"]
239
254
  stable.response.status = 200
240
255
  stable.response.write 'success'
@@ -257,7 +272,7 @@ end
257
272
  Thread.new do
258
273
  begin
259
274
  Stallion.run :Host => '127.0.0.1', :Port => 8090
260
- rescue Exception => e
275
+ rescue => e
261
276
  print e
262
277
  end
263
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.2
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Grigorik
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-20 00:00:00.000000000 Z
11
+ date: 2020-08-31 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
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
- 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,6 +215,7 @@ 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
@@ -220,24 +223,23 @@ homepage: http://github.com/igrigorik/em-http-request
220
223
  licenses:
221
224
  - MIT
222
225
  metadata: {}
223
- post_install_message:
226
+ post_install_message:
224
227
  rdoc_options: []
225
228
  require_paths:
226
229
  - lib
227
230
  required_ruby_version: !ruby/object:Gem::Requirement
228
231
  requirements:
229
- - - '>='
232
+ - - ">="
230
233
  - !ruby/object:Gem::Version
231
234
  version: '0'
232
235
  required_rubygems_version: !ruby/object:Gem::Requirement
233
236
  requirements:
234
- - - '>='
237
+ - - ">="
235
238
  - !ruby/object:Gem::Version
236
239
  version: '0'
237
240
  requirements: []
238
- rubyforge_project: em-http-request
239
- rubygems_version: 2.0.6
240
- signing_key:
241
+ rubygems_version: 3.0.3
242
+ signing_key:
241
243
  specification_version: 4
242
244
  summary: EventMachine based, async HTTP Request client
243
245
  test_files:
@@ -258,6 +260,7 @@ test_files:
258
260
  - spec/pipelining_spec.rb
259
261
  - spec/redirect_spec.rb
260
262
  - spec/socksify_proxy_spec.rb
263
+ - spec/spec_helper.rb
261
264
  - spec/ssl_spec.rb
262
265
  - spec/stallion.rb
263
266
  - spec/stub_server.rb