http-request 1.2.0 → 1.2.1

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.
@@ -2,6 +2,7 @@ require 'net/http'
2
2
  require 'net/https'
3
3
  require 'addressable/uri'
4
4
  require 'zlib'
5
+ require 'stringio'
5
6
 
6
7
  module HttpRequest
7
8
  extend self
@@ -89,7 +89,7 @@ module HttpRequest
89
89
  headers['User-Agent'] ||= user_agent
90
90
  headers['Connection'] ||= 'keep-alive' if keep_alive
91
91
  headers['Content-Length'] ||= body.bytesize.to_s if body
92
- headers['Accept-Encoding'] ||= 'gzip, deflate'
92
+ headers['Accept-Encoding'] ||= 'gzip' # TODO: add deflate support
93
93
 
94
94
  # Build request
95
95
  req_klass = instance_eval("Net::HTTP::"+verb.to_s.capitalize)
@@ -14,14 +14,16 @@ module HttpRequest
14
14
 
15
15
  # Auto deflate compressed content
16
16
  content_encoding = @header['content-encoding'].to_s.downcase
17
- if !content_encoding.empty? && (content_encoding.index('gzip') || content_encoding.index('deflate'))
17
+ if !content_encoding.empty? && content_encoding =~ /gzip/
18
18
  gz = Zlib::GzipReader.new(StringIO.new(@body))
19
+ @body = gz.read
19
20
  end
20
21
 
21
22
  # Use encoding suggested by charset
22
23
  charset = @header['content-type'].to_s.match(/charset=([a-z0-9-]*)/i).to_s
23
24
  if !charset.empty?
24
- @body.force_encoding(charset.split('=')[1]) rescue nil
25
+ encoding = Encoding.find(charset.split('=')[1]) rescue 'utf-8'
26
+ @body.force_encoding(encoding)
25
27
  end
26
28
  end
27
29
 
@@ -1,3 +1,3 @@
1
1
  module HttpRequest
2
- VERSION = '1.2.0'
2
+ VERSION = '1.2.1'
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.2.0
4
+ version: 1.2.1
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-12-11 00:00:00.000000000 Z
12
+ date: 2012-12-12 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: -1774260015767547978
89
+ hash: 2860803797911007449
90
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  none: false
92
92
  requirements: