em-http-request 1.1.3 → 1.1.4

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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6b892384de4aaa4e5983ce807f416814c0f5768
4
- data.tar.gz: e7a1f158af27740ba67b4515ae3e338dff44666d
3
+ metadata.gz: a07874f78e22e8d5050980f2c9bc898bb95a0cf7
4
+ data.tar.gz: 11853fc0cee6e4f6ec2f5b1bf13d0ad156085861
5
5
  SHA512:
6
- metadata.gz: 44faab083fdc1c80147ec45999ad6fc8490bfde5ee6dd5b9a06969ef7b49918c08e3c6fbc1eb552f527cfd17fca78fdcad2fc30bf4a62bb0fa2027b266b4f48a
7
- data.tar.gz: 74ee5fd141fb0055383e0befb7e7ed75c567273d445652187088c33dbe3a4d424ee0505b673953eb402248f066384e5c1b9ba2bc141b1b2560c67c441e9731f6
6
+ metadata.gz: a2599aea8d7c5a25f98bb4795bdeaca42de935afac3fce0ae1b705a53ff8bb82cfbe6fc8c76af1c3dcd7f68719af45e76c97f94b58dabec2eb1523c108a5397b
7
+ data.tar.gz: 5d7c7cab7d3ef0e594400a8c56e60943899da1122263f376bc602dad2dec88037f08cadf26de006b464bd3082445e6d403ddb76c2fc3f9a70f2c62db4130119a
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.4
4
+ script: bundle exec rake spec
5
+ notifications:
6
+ email:
7
+ - ilya@igvita.com
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # EM-HTTP-Request
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/em-http-request.png)](http://rubygems.org/gems/em-http-request)
4
- [![Analytics](https://ga-beacon.appspot.com/UA-71196-10/em-http-request/readme)](https://github.com/igrigorik/ga-beacon)
3
+ [![Gem Version](https://badge.fury.io/rb/em-http-request.png)](http://rubygems.org/gems/em-http-request) [![Build Status](https://travis-ci.org/igrigorik/em-http-request.svg)](https://travis-ci.org/igrigorik/em-http-request)
5
4
 
6
5
  Async (EventMachine) HTTP client, with support for:
7
6
 
@@ -13,7 +12,7 @@ Async (EventMachine) HTTP client, with support for:
13
12
  - Streaming file uploads
14
13
  - HTTP proxy and SOCKS5 support
15
14
  - Basic Auth & OAuth
16
- - Connection-level & Global middleware support
15
+ - Connection-level & global middleware support
17
16
  - HTTP parser via [http_parser.rb](https://github.com/tmm1/http_parser.rb)
18
17
  - Works wherever EventMachine runs: Rubinius, JRuby, MRI
19
18
 
@@ -21,7 +20,7 @@ Async (EventMachine) HTTP client, with support for:
21
20
 
22
21
  gem install em-http-request
23
22
 
24
- - Introductory [screencast](http://everburning.com/news/eventmachine-screencast-em-http-request/)
23
+ - Introductory [screencast](http://everburning.com/news/eventmachine-screencast-em-http-request)
25
24
  - [Issuing GET/POST/etc requests](https://github.com/igrigorik/em-http-request/wiki/Issuing-Requests)
26
25
  - [Issuing parallel requests with Multi interface](https://github.com/igrigorik/em-http-request/wiki/Parallel-Requests)
27
26
  - [Handling Redirects & Timeouts](https://github.com/igrigorik/em-http-request/wiki/Redirects-and-Timeouts)
@@ -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', '<= 0.3.0'
19
+ s.add_dependency 'cookiejar', '!= 0.3.1'
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'
@@ -155,11 +155,16 @@ module EventMachine
155
155
 
156
156
  # Set the User-Agent if it hasn't been specified
157
157
  if !head.key?('user-agent')
158
- head['user-agent'] = "EventMachine HttpClient"
158
+ head['user-agent'] = 'EventMachine HttpClient'
159
159
  elsif head['user-agent'].nil?
160
160
  head.delete('user-agent')
161
161
  end
162
162
 
163
+ # Set the Accept-Encoding header if none is provided
164
+ if !head.key?('accept-encoding') && req.compressed
165
+ head['accept-encoding'] = 'gzip, compressed'
166
+ end
167
+
163
168
  # Set the auth from the URI if given
164
169
  head['Authorization'] = @req.uri.userinfo.split(/:/, 2) if @req.uri.userinfo
165
170
 
@@ -1,7 +1,7 @@
1
1
  class HttpClientOptions
2
2
  attr_reader :uri, :method, :host, :port
3
3
  attr_reader :headers, :file, :body, :query, :path
4
- attr_reader :keepalive, :pass_cookies, :decoding
4
+ attr_reader :keepalive, :pass_cookies, :decoding, :compressed
5
5
 
6
6
  attr_accessor :followed, :redirects
7
7
 
@@ -18,6 +18,7 @@ class HttpClientOptions
18
18
 
19
19
  @pass_cookies = options.fetch(:pass_cookies, true) # pass cookies between redirects
20
20
  @decoding = options.fetch(:decoding, true) # auto-decode compressed response
21
+ @compressed = options.fetch(:compressed, true) # auto-negotiated compressed response
21
22
 
22
23
  set_uri(uri, options[:path], options[:query])
23
24
  end
@@ -20,6 +20,7 @@ class HttpConnectionOptions
20
20
  uri = uri.kind_of?(Addressable::URI) ? uri : Addressable::URI::parse(uri.to_s)
21
21
  @https = uri.scheme == "https"
22
22
  uri.port ||= (@https ? 443 : 80)
23
+ @tls[:sni_hostname] = uri.host
23
24
 
24
25
  if proxy = options[:proxy]
25
26
  @host = proxy[:host]
@@ -53,7 +53,12 @@ module EventMachine
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
55
  # cause 400 Bad Request errors with many standard setups.
56
- query = uri.join(query) if connopts.proxy && !connopts.connect_proxy?
56
+ if connopts.proxy && !connopts.connect_proxy?
57
+ query = uri.join(query)
58
+ # Drop the userinfo, it's been converted to a header and won't be
59
+ # accepted by the proxy
60
+ query.userinfo = nil
61
+ end
57
62
 
58
63
  HTTP_REQUEST_HEADER % [method.to_s.upcase, query]
59
64
  end
@@ -1,5 +1,5 @@
1
1
  module EventMachine
2
2
  class HttpRequest
3
- VERSION = "1.1.3"
3
+ VERSION = "1.1.4"
4
4
  end
5
5
  end
@@ -386,7 +386,7 @@ describe EventMachine::HttpRequest do
386
386
  }
387
387
  end
388
388
 
389
- it "should detect gzip encoding" do
389
+ it "should auto-detect and decode gzip encoding" do
390
390
  EventMachine.run {
391
391
 
392
392
  http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/gzip').get :head => {"accept-encoding" => "gzip, compressed"}
@@ -446,6 +446,36 @@ describe EventMachine::HttpRequest do
446
446
  }
447
447
  end
448
448
 
449
+ it "should default to requesting compressed response" do
450
+ EventMachine.run {
451
+
452
+ http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/echo_accept_encoding').get
453
+
454
+ http.errback { failed(http) }
455
+ http.callback {
456
+ http.response_header.status.should == 200
457
+ http.response.should == "gzip, compressed"
458
+
459
+ EventMachine.stop
460
+ }
461
+ }
462
+ end
463
+
464
+ it "should default to requesting compressed response" do
465
+ EventMachine.run {
466
+
467
+ http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/echo_accept_encoding').get :compressed => false
468
+
469
+ http.errback { failed(http) }
470
+ http.callback {
471
+ http.response_header.status.should == 200
472
+ http.response.should == ""
473
+
474
+ EventMachine.stop
475
+ }
476
+ }
477
+ end
478
+
449
479
  it "should timeout after 0.1 seconds of inactivity" do
450
480
  EventMachine.run {
451
481
  t = Time.now.to_i
@@ -52,6 +52,23 @@ describe EventMachine::HttpRequest do
52
52
  }
53
53
  end
54
54
 
55
+ it "should strip basic auth from before the host in URI sent to proxy" do
56
+ EventMachine.run {
57
+
58
+ http = EventMachine::HttpRequest.new('http://user:pass@127.0.0.1:8090/echo_authorization_header', proxy).get
59
+
60
+ http.errback { failed(http) }
61
+ http.callback {
62
+ http.response_header.status.should == 200
63
+ # The test proxy server gives the requested uri back in this header
64
+ http.response_header['X_THE_REQUESTED_URI'].should == 'http://127.0.0.1:8090/echo_authorization_header'
65
+ # Ensure the basic auth was converted to a header correctly
66
+ http.response.should match('authorization:Basic dXNlcjpwYXNz')
67
+ EventMachine.stop
68
+ }
69
+ }
70
+ end
71
+
55
72
  it "should include query parameters specified in the options" do
56
73
  EventMachine.run {
57
74
  http = EventMachine::HttpRequest.new('http://127.0.0.1:8090/', proxy).get :query => { 'q' => 'test' }
@@ -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.mexicodiario.com/')
11
+ conn = EventMachine::HttpRequest.new('http://www.bing.com/')
12
12
 
13
13
  pipe1 = conn.get :keepalive => true
14
- pipe2 = conn.get :path => '/contact/', :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.mexicodiario.com/')
39
+ conn = EventMachine::HttpRequest.new('http://www.bing.com/')
40
40
 
41
41
  pipe1 = conn.head :keepalive => true
42
- pipe2 = conn.head :path => '/contact/', :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}
@@ -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
 
@@ -235,6 +238,10 @@ Stallion.saddle :spec do |stable|
235
238
  stable.response.write deflater.finish
236
239
  stable.response["Content-Encoding"] = "deflate"
237
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
+
238
245
  elsif stable.request.env["HTTP_IF_NONE_MATCH"]
239
246
  stable.response.status = 304
240
247
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-http-request
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Grigorik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-20 00:00:00.000000000 Z
11
+ date: 2016-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -28,16 +28,16 @@ dependencies:
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.3.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.3.0
40
+ version: 0.3.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: em-socksify
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -160,6 +160,7 @@ files:
160
160
  - ".gemtest"
161
161
  - ".gitignore"
162
162
  - ".rspec"
163
+ - ".travis.yml"
163
164
  - Changelog.md
164
165
  - Gemfile
165
166
  - README.md
@@ -237,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
237
238
  version: '0'
238
239
  requirements: []
239
240
  rubyforge_project: em-http-request
240
- rubygems_version: 2.4.5.1
241
+ rubygems_version: 2.5.1
241
242
  signing_key:
242
243
  specification_version: 4
243
244
  summary: EventMachine based, async HTTP Request client
@@ -263,3 +264,4 @@ test_files:
263
264
  - spec/ssl_spec.rb
264
265
  - spec/stallion.rb
265
266
  - spec/stub_server.rb
267
+ has_rdoc: