http-request 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,9 @@
1
1
  require 'net/http'
2
2
  require 'net/https'
3
- require 'addressable/uri'
4
3
  require 'zlib'
5
4
  require 'stringio'
5
+ require 'addressable/uri'
6
+ require 'mime/types'
6
7
 
7
8
  module HttpRequest
8
9
  extend self
@@ -12,18 +12,25 @@ module HttpRequest
12
12
  header.each {|k,v| header[k] = v.first if v.is_a?(Array) && v.length == 1 }
13
13
  end
14
14
 
15
- # Auto deflate compressed content
15
+ # Auto decompress content
16
16
  content_encoding = @header['content-encoding'].to_s.downcase
17
17
  if !content_encoding.empty? && content_encoding =~ /gzip/
18
18
  gz = Zlib::GzipReader.new(StringIO.new(@body))
19
19
  @body = gz.read
20
20
  end
21
21
 
22
- # Use encoding suggested by charset
23
- charset = @header['content-type'].to_s.match(/charset=([a-z0-9-]*)/i).to_s
22
+ # Content type handling
23
+ content_type = @header['content-type'].to_s
24
+ charset = content_type.match(/charset=([a-z0-9-]*)/i).to_s
24
25
  if !charset.empty?
26
+ # Encode to suggested charset
25
27
  encoding = Encoding.find(charset.split('=')[1]) rescue 'utf-8'
26
28
  @body.force_encoding(encoding)
29
+ else
30
+ # Encode to utf-8 by default for any ascii content types
31
+ # that don't specify the charset
32
+ mime_type = MIME::Types[content_type].first
33
+ @body.force_encoding('utf-8') if mime_type && mime_type.ascii?
27
34
  end
28
35
  end
29
36
 
@@ -1,3 +1,3 @@
1
1
  module HttpRequest
2
- VERSION = '1.2.1'
2
+ VERSION = '1.2.2'
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.1
4
+ version: 1.2.2
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-12 00:00:00.000000000 Z
12
+ date: 2012-12-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: '2.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: mime-types
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.19'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.19'
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: rake
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -72,7 +88,7 @@ files:
72
88
  - lib/http-request/response.rb
73
89
  - lib/http-request/version.rb
74
90
  - lib/http-request.rb
75
- homepage: http://nulayer.com
91
+ homepage: https://github.com/nulayer/http-request
76
92
  licenses: []
77
93
  post_install_message:
78
94
  rdoc_options: []
@@ -86,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
102
  version: '0'
87
103
  segments:
88
104
  - 0
89
- hash: 2860803797911007449
105
+ hash: 4195676129085579668
90
106
  required_rubygems_version: !ruby/object:Gem::Requirement
91
107
  none: false
92
108
  requirements: