http-request 1.1.9 → 1.1.10

Sign up to get free protection for your applications and to get access to all the features.
data/lib/http-request.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'net/http'
2
2
  require 'net/https'
3
3
  require 'addressable/uri'
4
+ require 'zlib'
4
5
 
5
6
  module HttpRequest
6
7
  extend self
@@ -86,9 +86,10 @@ module HttpRequest
86
86
  open if closed?
87
87
 
88
88
  # Default headers
89
- headers['User-Agent'] ||= user_agent
90
- headers['Connection'] ||= 'keep-alive' if keep_alive
91
- headers['Content-Length'] ||= body.bytesize.to_s if body
89
+ headers['User-Agent'] ||= user_agent
90
+ headers['Connection'] ||= 'keep-alive' if keep_alive
91
+ headers['Content-Length'] ||= body.bytesize.to_s if body
92
+ headers['Accept-Encoding'] ||= 'gzip, deflate'
92
93
 
93
94
  # Build request
94
95
  req_klass = instance_eval("Net::HTTP::"+verb.to_s.capitalize)
@@ -11,6 +11,13 @@ module HttpRequest
11
11
  @header = net_http_response.header.to_hash.tap do |header|
12
12
  header.each {|k,v| header[k] = v.first if v.is_a?(Array) && v.length == 1 }
13
13
  end
14
+
15
+ # Auto deflate compressed content
16
+ content_encoding = @header['content-encoding'].to_s.downcase
17
+ if !content_encoding.empty? && (content_encoding.index('gzip') || content_encoding.index('deflate'))
18
+ gz = Zlib::GzipReader.new(StringIO.new(@body))
19
+ @body = gz.read
20
+ end
14
21
  end
15
22
 
16
23
  def status_message
@@ -1,3 +1,3 @@
1
1
  module HttpRequest
2
- VERSION = '1.1.9'
2
+ VERSION = '1.1.10'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-request
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.9
4
+ version: 1.1.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-18 00:00:00.000000000 Z
12
+ date: 2012-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
@@ -86,7 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
86
  version: '0'
87
87
  segments:
88
88
  - 0
89
- hash: 374309681473749968
89
+ hash: 4173997443445813792
90
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  none: false
92
92
  requirements: