http 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of http might be problematic. Click here for more details.

Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/.travis.yml +1 -1
  4. data/CHANGES.md +39 -27
  5. data/Gemfile +12 -12
  6. data/Guardfile +13 -5
  7. data/README.md +32 -31
  8. data/Rakefile +1 -1
  9. data/http.gemspec +8 -9
  10. data/lib/http/headers.rb +59 -24
  11. data/lib/http/headers/mixin.rb +22 -1
  12. data/lib/http/response.rb +1 -1
  13. data/lib/http/version.rb +1 -1
  14. data/spec/{http → lib/http}/client_spec.rb +0 -2
  15. data/spec/{http → lib/http}/content_type_spec.rb +0 -2
  16. data/spec/{http → lib/http}/headers/mixin_spec.rb +0 -2
  17. data/spec/{http → lib/http}/headers_spec.rb +8 -2
  18. data/spec/{http → lib/http}/options/body_spec.rb +0 -4
  19. data/spec/{http → lib/http}/options/form_spec.rb +0 -4
  20. data/spec/{http → lib/http}/options/headers_spec.rb +0 -4
  21. data/spec/{http → lib/http}/options/json_spec.rb +0 -4
  22. data/spec/{http → lib/http}/options/merge_spec.rb +0 -2
  23. data/spec/{http → lib/http}/options/new_spec.rb +0 -2
  24. data/spec/{http → lib/http}/options/proxy_spec.rb +0 -3
  25. data/spec/{http → lib/http}/options_spec.rb +0 -2
  26. data/spec/{http → lib/http}/redirector_spec.rb +0 -2
  27. data/spec/{http → lib/http}/request/writer_spec.rb +0 -2
  28. data/spec/{http → lib/http}/request_spec.rb +0 -2
  29. data/spec/{http → lib/http}/response/body_spec.rb +0 -2
  30. data/spec/{http → lib/http}/response/status_spec.rb +0 -2
  31. data/spec/{http → lib/http}/response_spec.rb +0 -2
  32. data/spec/{http_spec.rb → lib/http_spec.rb} +0 -1
  33. data/spec/spec_helper.rb +72 -18
  34. data/spec/support/capture_warning.rb +8 -0
  35. metadata +50 -47
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc19474bee4f52564c7c3e7da6a3223aa9854a1e
4
- data.tar.gz: 9f6d3dcf7a3ed0bedd9de9ae38fee5d4cba2f40b
3
+ metadata.gz: 02788674d1c33bccb2b1ce3ce9740c375dfd279e
4
+ data.tar.gz: f53920c45b63f890d6f53f63825f2876995f18f2
5
5
  SHA512:
6
- metadata.gz: c5521514cdfa5e30a2e876d492b0ee4d3be1689f0f26fe9258d6c86e6b08ee71521763902042a7ecf2512daf2da6ddd346f84f0c92a9baf9d9c815eb1bac8f57
7
- data.tar.gz: e1976feb1290b9466bf9de7ffa5050163aac481a88df2557d468d42cc7e2218fd34c202cec47247f008ab3c5c54024c61ba52cd3fadbee1fa064424cdddf1929
6
+ metadata.gz: a6e9a8742a612eba91e4b1de6853817a573ffba2942c8b1cc2813b6f365554eca31d1e613b4aedbafc94228393fd61655e892068702b5d86c908898a57176724
7
+ data.tar.gz: 6a3e72f0d8271682adc939e6619f839183ab1cd283913004e39ceeda998db1ec5c6334f55c4bc2214e269495c9b9f84f2c510cbf92337433420fd8cd7e465a81
data/.rspec CHANGED
@@ -2,4 +2,5 @@
2
2
  --color
3
3
  --format=documentation
4
4
  --order random
5
+ --require spec_helper
5
6
  --warnings
data/.travis.yml CHANGED
@@ -8,7 +8,7 @@ rvm:
8
8
  - 2.0.0
9
9
  - 2.1
10
10
  - 2.2
11
- - jruby-19mode
11
+ - jruby
12
12
  - jruby-head
13
13
  - ruby-head
14
14
  - rbx-2
data/CHANGES.md CHANGED
@@ -1,5 +1,10 @@
1
- 0.7.0 (2015-01-02)
2
- ------------------
1
+ ## 0.7.1 (2015-01-03)
2
+
3
+ * Gemspec fixups
4
+ * Remove superfluous space in HTTP::Response inspection
5
+
6
+
7
+ ## 0.7.0 (2015-01-02)
3
8
 
4
9
  * Fix handling of EOF which caused infinite loop. See #163, #166 and #152. (@mickm, @ixti)
5
10
  * Drop Ruby 1.8.7 support. (@ixti)
@@ -22,13 +27,13 @@
22
27
  deprecated (@ixti)
23
28
  * Delegate `HTTP::Response#readpartial` to `HTTP::Response::Body` (@ixti)
24
29
 
25
- 0.6.3 (2014-11-14)
26
- ------------------
30
+
31
+ ## 0.6.3 (2014-11-14)
27
32
 
28
33
  * Backported EOF fix from master branch. See #166. (@ixti)
29
34
 
30
- 0.6.2 (2014-08-06)
31
- ------------------
35
+
36
+ ## 0.6.2 (2014-08-06)
32
37
 
33
38
  * Fix default Host header value. See #150. (@ixti)
34
39
  * Deprecate BearerToken authorization header. (@ixti)
@@ -36,8 +41,8 @@
36
41
  * Rename `HTTP.with_follow` to `HTTP.follow` and mark former one as being
37
42
  deprecated (@ixti)
38
43
 
39
- 0.6.1 (2014-05-07)
40
- ------------------
44
+
45
+ ## 0.6.1 (2014-05-07)
41
46
 
42
47
  * Fix request `Content-Length` calculation for Unicode (@challengeechallengee)
43
48
  * Add `Response#flush` (@ixti)
@@ -46,8 +51,8 @@
46
51
  * Fix forgotten CGI require (@ixti)
47
52
  * Improve README (@tarcieri)
48
53
 
49
- 0.6.0 (2014-04-04)
50
- ------------------
54
+
55
+ ## 0.6.0 (2014-04-04)
51
56
 
52
57
  * Rename `HTTP::Request#method` to `HTTP::Request#verb` (@krainboltgreene)
53
58
  * Add `HTTP::ResponseBody` class (@tarcieri)
@@ -109,16 +114,17 @@ File.open "/tmp/dummy.bin", "wb" do |io|
109
114
  end
110
115
  ```
111
116
 
112
- [Changes discussion](https://github.com/tarcieri/http/issues/116)
117
+ [Changes discussion](https://github.com/httprb/http.rb/issues/116)
118
+
113
119
 
114
- 0.5.1 (2014-05-27)
115
- ------------------
120
+ ## 0.5.1 (2014-05-27)
116
121
 
117
122
  * Backports redirector fixes from 0.6.0 (@ixti)
118
123
  * EOL of 0.5.X branch.
119
124
 
120
- 0.5.0
121
- -----
125
+
126
+ ## 0.5.0 (2013-09-14)
127
+
122
128
  * Add query string support
123
129
  * New response delegator allows HTTP.get(uri).response
124
130
  * HTTP::Chainable#stream provides a shorter alias for
@@ -126,36 +132,42 @@ end
126
132
  * Better string inspect for HTTP::Response
127
133
  * Curb compatibility layer removed
128
134
 
129
- 0.4.0
130
- -----
135
+
136
+ ## 0.4.0 (2012-10-12)
137
+
131
138
  * Fix bug accessing https URLs
132
139
  * Fix several instances of broken redirect handling
133
140
  * Add default user agent
134
141
  * Many additional minor bugfixes
135
142
 
136
- 0.3.0
137
- -----
143
+
144
+ ## 0.3.0 (2012-09-01)
145
+
138
146
  * New implementation based on tmm1's http_parser.rb instead of Net::HTTP
139
147
  * Support for following redirects
140
148
  * Support for request body through {:body => ...} option
141
149
  * HTTP#with_response (through Chainable)
142
150
 
143
- 0.2.0
144
- -----
151
+
152
+ ## 0.2.0 (2012-03-05)
153
+
145
154
  * Request and response objects
146
155
  * Callback system
147
156
  * Internal refactoring ensuring true chainability
148
157
  * Use the certified gem to ensure SSL certificate verification
149
158
 
150
- 0.1.0
151
- -----
159
+
160
+ ## 0.1.0 (2012-01-26)
161
+
152
162
  * Testing against WEBrick
153
163
  * Curb compatibility (require 'http/compat/curb')
154
164
 
155
- 0.0.1
156
- -----
165
+
166
+ ## 0.0.1 (2011-10-11)
167
+
157
168
  * Initial half-baked release
158
169
 
159
- 0.0.0
160
- -----
170
+
171
+ ## 0.0.0 (2011-10-06)
172
+
161
173
  * Vapoware release to claim the "http" gem name >:D
data/Gemfile CHANGED
@@ -1,36 +1,36 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'jruby-openssl' if defined? JRUBY_VERSION
4
4
  gem 'rake'
5
5
 
6
6
  group :development do
7
+ gem 'celluloid-io'
8
+ gem 'guard'
9
+ gem 'guard-rspec'
7
10
  gem 'pry'
11
+
8
12
  platforms :ruby_19, :ruby_20 do
9
13
  gem 'pry-debugger'
10
14
  gem 'pry-stack_explorer'
11
15
  end
12
- platforms :ruby_19, :ruby_20, :ruby_21 do
13
- gem 'celluloid-io'
14
- gem 'guard-rspec'
15
- end
16
16
  end
17
17
 
18
18
  group :test do
19
19
  gem 'backports'
20
20
  gem 'coveralls'
21
- gem 'json', '>= 1.8.1', :platforms => [:jruby, :rbx, :ruby_19]
22
- gem 'mime-types', '~> 1.25', :platforms => [:jruby]
23
- gem 'rest-client', '~> 1.6.0', :platforms => [:jruby]
24
- gem 'rspec', '~> 3.0'
21
+ gem 'json', '>= 1.8.1'
22
+ gem 'mime-types', '~> 1.25', :platforms => [:jruby]
23
+ gem 'rest-client', '~> 1.6.0', :platforms => [:jruby]
24
+ gem 'rspec', '~> 3.0'
25
25
  gem 'rspec-its'
26
- gem 'rubocop', '~> 0.25.0', :platforms => [:ruby_19, :ruby_20, :ruby_21]
27
- gem 'simplecov', '>= 0.9'
26
+ gem 'rubocop', '~> 0.25.0'
27
+ gem 'simplecov', '>= 0.9'
28
28
  gem 'yardstick'
29
29
  end
30
30
 
31
31
  group :doc do
32
- gem 'yard'
33
32
  gem 'redcarpet'
33
+ gem 'yard'
34
34
  end
35
35
 
36
36
  # Specify your gem's dependencies in http.gemspec
data/Guardfile CHANGED
@@ -1,8 +1,16 @@
1
- # A sample Guardfile
2
1
  # More info at https://github.com/guard/guard#readme
3
2
 
4
- guard :rspec do
5
- watch(/^spec\/.+_spec\.rb$/)
6
- watch(/^lib\/(.+)\.rb$/) { |m| "spec/#{m[1]}_spec.rb" }
7
- watch('spec/spec_helper.rb') { 'spec' }
3
+ guard :rspec, :cmd => 'bundle exec rspec' do
4
+ require 'guard/rspec/dsl'
5
+ dsl = Guard::RSpec::Dsl.new(self)
6
+
7
+ # RSpec files
8
+ rspec = dsl.rspec
9
+ watch(rspec.spec_helper) { rspec.spec_dir }
10
+ watch(rspec.spec_support) { rspec.spec_dir }
11
+ watch(rspec.spec_files)
12
+
13
+ # Ruby files
14
+ ruby = dsl.ruby
15
+ dsl.watch_spec_files_for(ruby.lib_files)
8
16
  end
data/README.md CHANGED
@@ -23,12 +23,13 @@ Help and Discussion
23
23
  -------------------
24
24
 
25
25
  If you need help or just want to talk about the http.rb,
26
- [visit the http.rb Google Group][googlegroup],
27
- or join by email by sending a message to:
28
- [httprb+subscribe@googlegroups.com][subscribe].
26
+ visit the http.rb Google Group:
29
27
 
30
- [googlegroup]: https://groups.google.com/forum/#!forum/httprb
31
- [subscribe]: mailto:httprb+subscribe@googlegroups.com
28
+ https://groups.google.com/forum/#!forum/httprb
29
+
30
+ You can join by email by sending a message to:
31
+
32
+ [httprb+subscribe@googlegroups.com](mailto:httprb+subscribe@googlegroups.com)
32
33
 
33
34
  If you believe you've found a bug, please report it at:
34
35
 
@@ -58,7 +59,7 @@ Inside of your Ruby program do:
58
59
  Documentation
59
60
  -------------
60
61
 
61
- [Please see the http.rb wiki](https://github.com/httprb/http/wiki)
62
+ [Please see the http.rb wiki](https://github.com/httprb/http.rb/wiki)
62
63
  for more detailed documentation and usage notes.
63
64
 
64
65
  Basic Usage
@@ -69,7 +70,7 @@ Here's some simple examples to get you started:
69
70
  ### GET requests
70
71
 
71
72
  ```ruby
72
- >> HTTP.get("http://www.google.com").to_s
73
+ >> HTTP.get('https://github.com').to_s
73
74
  => "<html><head><meta http-equiv=\"content-type\" content=..."
74
75
  ```
75
76
 
@@ -77,26 +78,26 @@ That's all it takes! To obtain an `HTTP::Response` object instead of the respons
77
78
  body, all we have to do is omit the #to_s on the end:
78
79
 
79
80
  ```ruby
80
- >> HTTP.get("http://www.google.com")
81
+ >> HTTP.get('https://github.com')
81
82
  => #<HTTP/1.0 200 OK @headers={"Content-Type"=>"text/html; charset=UTF-8", "Date"=>"Fri, ...>
82
83
  => #<HTTP::Response/1.1 200 OK @headers={"Content-Type"=>"text/html; ...>
83
84
  ```
84
85
 
85
- We can also obtain an `HTTP::ResponseBody` object for this response:
86
+ We can also obtain an `HTTP::Response::Body` object for this response:
86
87
 
87
88
  ```ruby
88
- >> HTTP.get("http://www.google.com").body
89
- => #<HTTP::ResponseBody:814d7aac @streaming=false>
89
+ >> HTTP.get('https://github.com').body
90
+ => #<HTTP::Response::Body:814d7aac @streaming=false>
90
91
  ```
91
92
 
92
- The response body can be streamed with `HTTP::ResponseBody#readpartial`:
93
+ The response body can be streamed with `HTTP::Response::Body#readpartial`:
93
94
 
94
95
  ```ruby
95
- >> HTTP.get("http://www.google.com").body.readpartial
96
+ >> HTTP.get('https://github.com').body.readpartial
96
97
  => "<!doctype html><html "
97
98
  ```
98
99
 
99
- In practice you'll want to bind the HTTP::ResponseBody to a local variable (e.g.
100
+ In practice you'll want to bind the HTTP::Response::Body to a local variable (e.g.
100
101
  "body") and call readpartial on it repeatedly until it returns nil.
101
102
 
102
103
  ### POST requests
@@ -104,24 +105,24 @@ In practice you'll want to bind the HTTP::ResponseBody to a local variable (e.g.
104
105
  Making POST requests is simple too. Want to POST a form?
105
106
 
106
107
  ```ruby
107
- HTTP.post("http://example.com/resource", :form => {:foo => "42"})
108
+ HTTP.post('http://example.com/resource', :form => {:foo => '42'})
108
109
  ```
109
110
  Making GET requests with query string parameters is as simple.
110
111
 
111
112
  ```ruby
112
- HTTP.get("http://example.com/resource", :params => {:foo => "bar"})
113
+ HTTP.get('http://example.com/resource', :params => {:foo => 'bar'})
113
114
  ```
114
115
 
115
116
  Want to POST with a specific body, JSON for instance?
116
117
 
117
118
  ```ruby
118
- HTTP.post("http://example.com/resource", :json => { :foo => '42' })
119
+ HTTP.post('http://example.com/resource', :json => { :foo => '42' })
119
120
  ```
120
121
 
121
122
  Or just a plain body?
122
123
 
123
124
  ```ruby
124
- HTTP.post("http://example.com/resource", :body => "foo=42&bar=baz")
125
+ HTTP.post('http://example.com/resource', :body => 'foo=42&bar=baz')
125
126
  ```
126
127
 
127
128
  It's easy!
@@ -132,15 +133,15 @@ Making request behind proxy is as simple as making them directly. Just specify
132
133
  hostname (or IP address) of your proxy server and its port, and here you go:
133
134
 
134
135
  ```ruby
135
- HTTP.via("proxy-hostname.local", 8080)
136
- .get "http://example.com/resource"
136
+ HTTP.via('proxy-hostname.local', 8080)
137
+ .get('http://example.com/resource')
137
138
  ```
138
139
 
139
140
  Proxy needs authentication? No problem:
140
141
 
141
142
  ```ruby
142
- HTTP.via("proxy-hostname.local", 8080, "username", "password")
143
- .get "http://example.com/resource"
143
+ HTTP.via('proxy-hostname.local', 8080, 'username', 'password')
144
+ .get('http://example.com/resource')
144
145
  ```
145
146
 
146
147
  ### Adding Headers
@@ -150,7 +151,7 @@ you want to get the latest commit of this library from GitHub in JSON format.
150
151
  One way we could do this is by tacking a filename on the end of the URL:
151
152
 
152
153
  ```ruby
153
- HTTP.get("https://github.com/httprb/http/commit/HEAD.json")
154
+ HTTP.get('https://github.com/httprb/http.rb/commit/HEAD.json')
154
155
  ```
155
156
 
156
157
  The GitHub API happens to support this approach, but really this is a bit of a
@@ -161,7 +162,7 @@ intends us to, by using the Accept header:
161
162
 
162
163
  ```ruby
163
164
  HTTP.with_headers(:accept => 'application/json').
164
- get("https://github.com/httprb/http/commit/HEAD")
165
+ get('https://github.com/httprb/http.rb/commit/HEAD')
165
166
  ```
166
167
 
167
168
  This requests JSON from GitHub. GitHub is smart enough to understand our
@@ -171,16 +172,16 @@ Shorter aliases exists for HTTP.with_headers:
171
172
 
172
173
  ```ruby
173
174
  HTTP.with(:accept => 'application/json').
174
- get("https://github.com/httprb/http/commit/HEAD")
175
+ get('https://github.com/httprb/http.rb/commit/HEAD')
175
176
 
176
177
  HTTP[:accept => 'application/json'].
177
- get("https://github.com/httprb/http/commit/HEAD")
178
+ get('https://github.com/httprb/http.rb/commit/HEAD')
178
179
  ```
179
180
 
180
181
  ### Authorization Header
181
182
 
182
- With [HTTP Basic Authentication](http://tools.ietf.org/html/rfc2617) username
183
- and password:
183
+ With [HTTP Basic Authentication](http://tools.ietf.org/html/rfc2617) using
184
+ a username and password:
184
185
 
185
186
  ```ruby
186
187
  HTTP.basic_auth(:user => 'user', :pass => 'pass')
@@ -190,7 +191,7 @@ HTTP.basic_auth(:user => 'user', :pass => 'pass')
190
191
  Or with plain as-is value:
191
192
 
192
193
  ```ruby
193
- HTTP.auth("Bearer VGhlIEhUVFAgR2VtLCBST0NLUw")
194
+ HTTP.auth('Bearer VGhlIEhUVFAgR2VtLCBST0NLUw')
194
195
  # <HTTP::Headers {"Authorization"=>"Bearer VGhlIEhUVFAgR2VtLCBST0NLUw"}>
195
196
  ```
196
197
 
@@ -209,7 +210,7 @@ right? But usually it's not, and so we end up adding ".json" onto the ends of
209
210
  our URLs because the existing mechanisms make it too hard. It should be easy:
210
211
 
211
212
  ```ruby
212
- HTTP.accept(:json).get("https://github.com/httprb/http/commit/HEAD")
213
+ HTTP.accept(:json).get('https://github.com/httprb/http.rb/commit/HEAD')
213
214
  ```
214
215
 
215
216
  This adds the appropriate Accept header for retrieving a JSON response for the
@@ -236,7 +237,7 @@ end
236
237
 
237
238
  There's a little more to it, but that's the core idea!
238
239
 
239
- * [Full parallel HTTP fetcher example](https://github.com/httprb/http/wiki/Parallel-requests-with-Celluloid%3A%3AIO)
240
+ * [Full parallel HTTP fetcher example](https://github.com/httprb/http.rb/wiki/Parallel-requests-with-Celluloid%3A%3AIO)
240
241
  * See also: [Celluloid::IO](https://github.com/celluloid/celluloid-io)
241
242
 
242
243
  Supported Ruby Versions
data/Rakefile CHANGED
@@ -23,7 +23,7 @@ end
23
23
  require 'yardstick/rake/verify'
24
24
  Yardstick::Rake::Verify.new do |verify|
25
25
  verify.require_exact_threshold = false
26
- verify.threshold = 58.8
26
+ verify.threshold = 58
27
27
  end
28
28
 
29
29
  task :default => [:spec, :rubocop, :verify_measurements]
data/http.gemspec CHANGED
@@ -1,10 +1,9 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'http/version'
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/http/version', __FILE__)
4
3
 
5
4
  Gem::Specification.new do |gem|
6
- gem.authors = %w(Tony Arcieri)
7
- gem.email = %w(tony.arcieri@gmail.com)
5
+ gem.authors = ['Tony Arcieri', 'Erik Michaels-Ober', 'Aleksey V. Zapparov']
6
+ gem.email = ['bascule@gmail.com']
8
7
 
9
8
  gem.description = <<-DESCRIPTION.strip.gsub(/\s+/, ' ')
10
9
  An easy-to-use client library for making requests from Ruby.
@@ -13,18 +12,18 @@ Gem::Specification.new do |gem|
13
12
  DESCRIPTION
14
13
 
15
14
  gem.summary = 'HTTP should be easy'
16
- gem.homepage = 'https://github.com/tarcieri/http.rb'
17
- gem.licenses = %w(MIT)
15
+ gem.homepage = 'https://github.com/httprb/http.rb'
16
+ gem.licenses = ['MIT']
18
17
 
19
18
  gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
20
19
  gem.files = `git ls-files`.split("\n")
21
20
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
21
  gem.name = 'http'
23
- gem.require_paths = %w(lib)
22
+ gem.require_paths = ['lib']
24
23
  gem.version = HTTP::VERSION
25
24
 
26
25
  gem.add_runtime_dependency 'http_parser.rb', '~> 0.6.0'
27
- gem.add_runtime_dependency 'form_data', '~> 0.0.1'
26
+ gem.add_runtime_dependency 'form_data', '~> 0.1.0'
28
27
 
29
28
  gem.add_development_dependency 'bundler', '~> 1.0'
30
29
  end
data/lib/http/headers.rb CHANGED
@@ -3,6 +3,7 @@ require 'forwardable'
3
3
  require 'http/headers/mixin'
4
4
 
5
5
  module HTTP
6
+ # HTTP Headers container.
6
7
  class Headers
7
8
  extend Forwardable
8
9
  include Enumerable
@@ -10,13 +11,14 @@ module HTTP
10
11
  # Matches HTTP header names when in "Canonical-Http-Format"
11
12
  CANONICAL_HEADER = /^[A-Z][a-z]*(-[A-Z][a-z]*)*$/
12
13
 
13
- # :nodoc:
14
+ # Class constructor.
14
15
  def initialize
15
16
  @pile = []
16
17
  end
17
18
 
18
- # Sets header
19
+ # Sets header.
19
20
  #
21
+ # @param (see #add)
20
22
  # @return [void]
21
23
  def set(name, value)
22
24
  delete(name)
@@ -24,36 +26,41 @@ module HTTP
24
26
  end
25
27
  alias_method :[]=, :set
26
28
 
27
- # Removes header
29
+ # Removes header.
28
30
  #
31
+ # @param [#to_s] name header name
29
32
  # @return [void]
30
33
  def delete(name)
31
34
  name = canonicalize_header name.to_s
32
35
  @pile.delete_if { |k, _| k == name }
33
36
  end
34
37
 
35
- # Append header
38
+ # Appends header.
36
39
  #
40
+ # @param [#to_s] name header name
41
+ # @param [Array<#to_s>, #to_s] value header value(s) to be appended
37
42
  # @return [void]
38
43
  def add(name, value)
39
- name = canonicalize_header name.to_s
40
- Array(value).each { |v| @pile << [name, v] }
44
+ name = canonicalize_header name.to_s
45
+ Array(value).each { |v| @pile << [name, v.to_s] }
41
46
  end
47
+
48
+ # @deprecated Will be removed in 1.0.0
42
49
  alias_method :append, :add
43
50
 
44
- # Return array of header values if any.
51
+ # Returns list of header values if any.
45
52
  #
46
- # @return [Array]
53
+ # @return [Array<String>]
47
54
  def get(name)
48
55
  name = canonicalize_header name.to_s
49
56
  @pile.select { |k, _| k == name }.map { |_, v| v }
50
57
  end
51
58
 
52
- # Smart version of {#get}
59
+ # Smart version of {#get}.
53
60
  #
54
- # @return [NilClass] if header was not set
55
- # @return [Object] if header has exactly one value
56
- # @return [Array<Object>] if header has more than one value
61
+ # @return [nil] if header was not set
62
+ # @return [String] if header has exactly one value
63
+ # @return [Array<String>] if header has more than one value
57
64
  def [](name)
58
65
  values = get(name)
59
66
 
@@ -64,26 +71,28 @@ module HTTP
64
71
  end
65
72
  end
66
73
 
67
- # Converts headers into a Rack-compatible Hash
74
+ # Returns Rack-compatible headers Hash
68
75
  #
69
76
  # @return [Hash]
70
77
  def to_h
71
78
  Hash[keys.map { |k| [k, self[k]] }]
72
79
  end
73
80
 
74
- # Array of key/value pairs
81
+ # Returns headers key/value pairs.
75
82
  #
76
83
  # @return [Array<[String, String]>]
77
84
  def to_a
78
85
  @pile.map { |pair| pair.map(&:dup) }
79
86
  end
80
87
 
81
- # :nodoc:
88
+ # Returns human-readable representation of `self` instance.
89
+ #
90
+ # @return [String]
82
91
  def inspect
83
92
  "#<#{self.class} #{to_h.inspect}>"
84
93
  end
85
94
 
86
- # List of header names
95
+ # Returns list of header names.
87
96
  #
88
97
  # @return [Array<String>]
89
98
  def keys
@@ -98,15 +107,40 @@ module HTTP
98
107
  @pile == other.to_a
99
108
  end
100
109
 
101
- def_delegators :@pile, :each, :empty?, :hash
110
+ # Calls the given block once for each key/value pair in headers container.
111
+ #
112
+ # @return [Enumerator] if no block given
113
+ # @return [Headers] self-reference
114
+ def each(&blk)
115
+ return @pile.each unless blk
116
+
117
+ @pile.each(&blk)
118
+ self
119
+ end
102
120
 
103
- # :nodoc:
121
+ # @!method empty?
122
+ # Returns `true` if `self` has no key/value pairs
123
+ #
124
+ # @return [Boolean]
125
+ def_delegator :@pile, :empty?
126
+
127
+ # @!method hash
128
+ # Compute a hash-code for this headers container.
129
+ # Two conatiners with the same content will have the same hash code.
130
+ #
131
+ # @see http://www.ruby-doc.org/core/Object.html#method-i-hash
132
+ # @return [Fixnum]
133
+ def_delegator :@pile, :hash
134
+
135
+ # Properly clones internal key/value storage.
136
+ #
137
+ # @api private
104
138
  def initialize_copy(orig)
105
139
  super
106
140
  @pile = to_a
107
141
  end
108
142
 
109
- # Merge in `other` headers
143
+ # Merges `other` headers into `self`.
110
144
  #
111
145
  # @see #merge
112
146
  # @return [void]
@@ -114,7 +148,7 @@ module HTTP
114
148
  self.class.coerce(other).to_h.each { |name, values| set name, values }
115
149
  end
116
150
 
117
- # Returns new Headers instance with `other` headers merged in.
151
+ # Returns new instance with `other` headers merged in.
118
152
  #
119
153
  # @see #merge!
120
154
  # @return [Headers]
@@ -123,9 +157,9 @@ module HTTP
123
157
  end
124
158
 
125
159
  class << self
126
- # Initiates new Headers object from given object.
160
+ # Coerces given `object` into Headers.
127
161
  #
128
- # @raise [Error] if given object can't be coerced
162
+ # @raise [Error] if object can't be coerced
129
163
  # @param [#to_hash, #to_h, #to_a] object
130
164
  # @return [Headers]
131
165
  def coerce(object)
@@ -147,9 +181,10 @@ module HTTP
147
181
 
148
182
  private
149
183
 
150
- # Transform to canonical HTTP header capitalization
184
+ # Transforms `name` to canonical HTTP header capitalization
185
+ #
151
186
  # @param [String] name
152
- # @return [String]
187
+ # @return [String] canonical HTTP header name
153
188
  def canonicalize_header(name)
154
189
  name[CANONICAL_HEADER] || name.split(/[\-_]/).map(&:capitalize).join('-')
155
190
  end
@@ -2,10 +2,31 @@ require 'forwardable'
2
2
 
3
3
  module HTTP
4
4
  class Headers
5
+ # Provides shared behavior for {HTTP::Request} and {HTTP::Response}.
6
+ # Expects `@headers` to be an instance of {HTTP::Headers}.
7
+ #
8
+ # @example Usage
9
+ #
10
+ # class MyHttpRequest
11
+ # include HTTP::Headers::Mixin
12
+ #
13
+ # def initialize
14
+ # @headers = HTTP::Headers.new
15
+ # end
16
+ # end
5
17
  module Mixin
6
18
  extend Forwardable
19
+
20
+ # @return [HTTP::Headers]
7
21
  attr_reader :headers
8
- def_delegators :headers, :[], :[]=
22
+
23
+ # @!method []
24
+ # (see HTTP::Headers#[])
25
+ def_delegator :headers, :[]
26
+
27
+ # @!method []=
28
+ # (see HTTP::Headers#[]=)
29
+ def_delegator :headers, :[]=
9
30
  end
10
31
  end
11
32
  end
data/lib/http/response.rb CHANGED
@@ -102,7 +102,7 @@ module HTTP
102
102
 
103
103
  # Inspect a response
104
104
  def inspect
105
- "#<#{self.class}/#{@version} #{code} #{reason} #{headers.inspect}>"
105
+ "#<#{self.class}/#{@version} #{code} #{reason} #{headers.inspect}>"
106
106
  end
107
107
  end
108
108
  end
data/lib/http/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module HTTP
2
- VERSION = '0.7.0'
2
+ VERSION = '0.7.1'
3
3
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe HTTP::Client do
4
2
  let(:test_endpoint) { "http://#{ExampleServer::ADDR}" }
5
3
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe HTTP::ContentType do
4
2
  describe '.parse' do
5
3
  context 'with text/plain' do
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe HTTP::Headers::Mixin do
4
2
  let :dummy_class do
5
3
  Class.new do
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe HTTP::Headers do
4
2
  subject(:headers) { described_class.new }
5
3
 
@@ -235,6 +233,14 @@ RSpec.describe HTTP::Headers do
235
233
  %w(Set-Cookie woo=hoo)
236
234
  )
237
235
  end
236
+
237
+ it 'returns self instance if block given' do
238
+ expect(headers.each { |*| }).to be headers
239
+ end
240
+
241
+ it 'returns Enumerator if no block given' do
242
+ expect(headers.each).to be_a Enumerator
243
+ end
238
244
  end
239
245
 
240
246
  describe '.empty?' do
@@ -1,7 +1,4 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe HTTP::Options, 'body' do
4
-
5
2
  let(:opts) { HTTP::Options.new }
6
3
 
7
4
  it 'defaults to nil' do
@@ -13,5 +10,4 @@ RSpec.describe HTTP::Options, 'body' do
13
10
  expect(opts.body).to be nil
14
11
  expect(opts2.body).to eq('foo')
15
12
  end
16
-
17
13
  end
@@ -1,7 +1,4 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe HTTP::Options, 'form' do
4
-
5
2
  let(:opts) { HTTP::Options.new }
6
3
 
7
4
  it 'defaults to nil' do
@@ -13,5 +10,4 @@ RSpec.describe HTTP::Options, 'form' do
13
10
  expect(opts.form).to be nil
14
11
  expect(opts2.form).to eq(:foo => 42)
15
12
  end
16
-
17
13
  end
@@ -1,7 +1,4 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe HTTP::Options, 'headers' do
4
-
5
2
  let(:opts) { HTTP::Options.new }
6
3
 
7
4
  it 'defaults to be empty' do
@@ -18,5 +15,4 @@ RSpec.describe HTTP::Options, 'headers' do
18
15
  x = Struct.new(:to_hash).new('accept' => 'json')
19
16
  expect(opts.with_headers(x).headers['accept']).to eq('json')
20
17
  end
21
-
22
18
  end
@@ -1,7 +1,4 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe HTTP::Options, 'json' do
4
-
5
2
  let(:opts) { HTTP::Options.new }
6
3
 
7
4
  it 'defaults to nil' do
@@ -13,5 +10,4 @@ RSpec.describe HTTP::Options, 'json' do
13
10
  expect(opts.json).to be nil
14
11
  expect(opts2.json).to eq(:foo => 42)
15
12
  end
16
-
17
13
  end
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe HTTP::Options, 'merge' do
4
2
  let(:opts) { HTTP::Options.new }
5
3
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe HTTP::Options, 'new' do
4
2
  it 'supports a Options instance' do
5
3
  opts = HTTP::Options.new
@@ -1,7 +1,4 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe HTTP::Options, 'proxy' do
4
-
5
2
  let(:opts) { HTTP::Options.new }
6
3
 
7
4
  it 'defaults to {}' do
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe HTTP::Options do
4
2
  subject { described_class.new(:response => :body) }
5
3
 
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe HTTP::Redirector do
4
2
  def simple_response(status, body = '', headers = {})
5
3
  HTTP::Response.new(status, '1.1', headers, body)
@@ -1,7 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'spec_helper'
4
-
5
3
  RSpec.describe HTTP::Request::Writer do
6
4
  let(:io) { StringIO.new }
7
5
  let(:body) { '' }
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe HTTP::Request do
4
2
  let(:headers) { {:accept => 'text/html'} }
5
3
  let(:request_uri) { 'http://example.com/' }
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe HTTP::Response::Body do
4
2
  let(:client) { double }
5
3
  let(:chunks) { ['Hello, ', 'World!'] }
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe HTTP::Response::Status do
4
2
  describe '.new' do
5
3
  it 'fails if given value does not respond to #to_i' do
@@ -1,5 +1,3 @@
1
- require 'spec_helper'
2
-
3
1
  RSpec.describe HTTP::Response do
4
2
  it 'includes HTTP::Headers::Mixin' do
5
3
  expect(described_class).to include HTTP::Headers::Mixin
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
  require 'json'
3
2
 
4
3
  RSpec.describe HTTP do
data/spec/spec_helper.rb CHANGED
@@ -1,32 +1,86 @@
1
- if RUBY_VERSION >= '1.9'
2
- require 'simplecov'
3
- require 'coveralls'
1
+ # coding: utf-8
4
2
 
5
- SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
3
+ require 'simplecov'
4
+ require 'coveralls'
6
5
 
7
- SimpleCov.start do
8
- add_filter '/spec/'
9
- minimum_coverage(80)
10
- end
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
10
+
11
+ SimpleCov.start do
12
+ add_filter '/spec/'
13
+ minimum_coverage 80
11
14
  end
12
15
 
13
16
  require 'http'
14
17
  require 'rspec/its'
15
18
  require 'support/example_server'
16
19
  require 'support/proxy_server'
20
+ require 'support/capture_warning'
17
21
 
22
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
18
23
  RSpec.configure do |config|
24
+ config.expect_with :rspec do |expectations|
25
+ # This option will default to `true` in RSpec 4. It makes the `description`
26
+ # and `failure_message` of custom matchers include text for helper methods
27
+ # defined using `chain`, e.g.:
28
+ # be_bigger_than(2).and_smaller_than(4).description
29
+ # # => "be bigger than 2 and smaller than 4"
30
+ # ...rather than:
31
+ # # => "be bigger than 2"
32
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
33
+ end
34
+
35
+ config.mock_with :rspec do |mocks|
36
+ # Prevents you from mocking or stubbing a method that does not exist on
37
+ # a real object. This is generally recommended, and will default to
38
+ # `true` in RSpec 4.
39
+ mocks.verify_partial_doubles = true
40
+ end
41
+
42
+ # These two settings work together to allow you to limit a spec run
43
+ # to individual examples or groups you care about by tagging them with
44
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
45
+ # get run.
46
+ config.filter_run :focus
47
+ config.run_all_when_everything_filtered = true
48
+
49
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
50
+ # For more details, see:
51
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
52
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
53
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
19
54
  config.disable_monkey_patching!
20
- end
21
55
 
22
- def capture_warning
23
- begin
24
- old_stderr = $stderr
25
- $stderr = StringIO.new
26
- yield
27
- result = $stderr.string
28
- ensure
29
- $stderr = old_stderr
56
+ # This setting enables warnings. It's recommended, but in some cases may
57
+ # be too noisy due to issues in dependencies.
58
+ config.warnings = true
59
+
60
+ # Many RSpec users commonly either run the entire suite or an individual
61
+ # file, and it's useful to allow more verbose output when running an
62
+ # individual spec file.
63
+ if config.files_to_run.one?
64
+ # Use the documentation formatter for detailed output,
65
+ # unless a formatter has already been configured
66
+ # (e.g. via a command-line flag).
67
+ config.default_formatter = 'doc'
30
68
  end
31
- result
69
+
70
+ # Print the 10 slowest examples and example groups at the
71
+ # end of the spec run, to help surface which specs are running
72
+ # particularly slow.
73
+ config.profile_examples = 10
74
+
75
+ # Run specs in random order to surface order dependencies. If you find an
76
+ # order dependency and want to debug it, you can fix the order by providing
77
+ # the seed, which is printed after each run.
78
+ # --seed 1234
79
+ config.order = :random
80
+
81
+ # Seed global randomization in this process using the `--seed` CLI option.
82
+ # Setting this allows you to use `--seed` to deterministically reproduce
83
+ # test failures related to randomization by passing the same `--seed` value
84
+ # as the one that triggered the failure.
85
+ Kernel.srand config.seed
32
86
  end
@@ -0,0 +1,8 @@
1
+ def capture_warning
2
+ old_stderr = $stderr
3
+ $stderr = StringIO.new
4
+ yield
5
+ $stderr.string
6
+ ensure
7
+ $stderr = old_stderr
8
+ end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
- - Tony
8
- - Arcieri
7
+ - Tony Arcieri
8
+ - Erik Michaels-Ober
9
+ - Aleksey V. Zapparov
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2015-01-02 00:00:00.000000000 Z
13
+ date: 2015-01-03 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: http_parser.rb
@@ -31,14 +32,14 @@ dependencies:
31
32
  requirements:
32
33
  - - "~>"
33
34
  - !ruby/object:Gem::Version
34
- version: 0.0.1
35
+ version: 0.1.0
35
36
  type: :runtime
36
37
  prerelease: false
37
38
  version_requirements: !ruby/object:Gem::Requirement
38
39
  requirements:
39
40
  - - "~>"
40
41
  - !ruby/object:Gem::Version
41
- version: 0.0.1
42
+ version: 0.1.0
42
43
  - !ruby/object:Gem::Dependency
43
44
  name: bundler
44
45
  requirement: !ruby/object:Gem::Requirement
@@ -56,7 +57,7 @@ dependencies:
56
57
  description: An easy-to-use client library for making requests from Ruby. It uses
57
58
  a simple method chaining system for building requests, similar to Python's Requests.
58
59
  email:
59
- - tony.arcieri@gmail.com
60
+ - bascule@gmail.com
60
61
  executables: []
61
62
  extensions: []
62
63
  extra_rdoc_files: []
@@ -96,30 +97,31 @@ files:
96
97
  - lib/http/response/status/reasons.rb
97
98
  - lib/http/version.rb
98
99
  - logo.png
99
- - spec/http/client_spec.rb
100
- - spec/http/content_type_spec.rb
101
- - spec/http/headers/mixin_spec.rb
102
- - spec/http/headers_spec.rb
103
- - spec/http/options/body_spec.rb
104
- - spec/http/options/form_spec.rb
105
- - spec/http/options/headers_spec.rb
106
- - spec/http/options/json_spec.rb
107
- - spec/http/options/merge_spec.rb
108
- - spec/http/options/new_spec.rb
109
- - spec/http/options/proxy_spec.rb
110
- - spec/http/options_spec.rb
111
- - spec/http/redirector_spec.rb
112
- - spec/http/request/writer_spec.rb
113
- - spec/http/request_spec.rb
114
- - spec/http/response/body_spec.rb
115
- - spec/http/response/status_spec.rb
116
- - spec/http/response_spec.rb
117
- - spec/http_spec.rb
100
+ - spec/lib/http/client_spec.rb
101
+ - spec/lib/http/content_type_spec.rb
102
+ - spec/lib/http/headers/mixin_spec.rb
103
+ - spec/lib/http/headers_spec.rb
104
+ - spec/lib/http/options/body_spec.rb
105
+ - spec/lib/http/options/form_spec.rb
106
+ - spec/lib/http/options/headers_spec.rb
107
+ - spec/lib/http/options/json_spec.rb
108
+ - spec/lib/http/options/merge_spec.rb
109
+ - spec/lib/http/options/new_spec.rb
110
+ - spec/lib/http/options/proxy_spec.rb
111
+ - spec/lib/http/options_spec.rb
112
+ - spec/lib/http/redirector_spec.rb
113
+ - spec/lib/http/request/writer_spec.rb
114
+ - spec/lib/http/request_spec.rb
115
+ - spec/lib/http/response/body_spec.rb
116
+ - spec/lib/http/response/status_spec.rb
117
+ - spec/lib/http/response_spec.rb
118
+ - spec/lib/http_spec.rb
118
119
  - spec/spec_helper.rb
120
+ - spec/support/capture_warning.rb
119
121
  - spec/support/example_server.rb
120
122
  - spec/support/example_server/servlet.rb
121
123
  - spec/support/proxy_server.rb
122
- homepage: https://github.com/tarcieri/http.rb
124
+ homepage: https://github.com/httprb/http.rb
123
125
  licenses:
124
126
  - MIT
125
127
  metadata: {}
@@ -139,31 +141,32 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
141
  version: '0'
140
142
  requirements: []
141
143
  rubyforge_project:
142
- rubygems_version: 2.2.2
144
+ rubygems_version: 2.4.5
143
145
  signing_key:
144
146
  specification_version: 4
145
147
  summary: HTTP should be easy
146
148
  test_files:
147
- - spec/http/client_spec.rb
148
- - spec/http/content_type_spec.rb
149
- - spec/http/headers/mixin_spec.rb
150
- - spec/http/headers_spec.rb
151
- - spec/http/options/body_spec.rb
152
- - spec/http/options/form_spec.rb
153
- - spec/http/options/headers_spec.rb
154
- - spec/http/options/json_spec.rb
155
- - spec/http/options/merge_spec.rb
156
- - spec/http/options/new_spec.rb
157
- - spec/http/options/proxy_spec.rb
158
- - spec/http/options_spec.rb
159
- - spec/http/redirector_spec.rb
160
- - spec/http/request/writer_spec.rb
161
- - spec/http/request_spec.rb
162
- - spec/http/response/body_spec.rb
163
- - spec/http/response/status_spec.rb
164
- - spec/http/response_spec.rb
165
- - spec/http_spec.rb
149
+ - spec/lib/http/client_spec.rb
150
+ - spec/lib/http/content_type_spec.rb
151
+ - spec/lib/http/headers/mixin_spec.rb
152
+ - spec/lib/http/headers_spec.rb
153
+ - spec/lib/http/options/body_spec.rb
154
+ - spec/lib/http/options/form_spec.rb
155
+ - spec/lib/http/options/headers_spec.rb
156
+ - spec/lib/http/options/json_spec.rb
157
+ - spec/lib/http/options/merge_spec.rb
158
+ - spec/lib/http/options/new_spec.rb
159
+ - spec/lib/http/options/proxy_spec.rb
160
+ - spec/lib/http/options_spec.rb
161
+ - spec/lib/http/redirector_spec.rb
162
+ - spec/lib/http/request/writer_spec.rb
163
+ - spec/lib/http/request_spec.rb
164
+ - spec/lib/http/response/body_spec.rb
165
+ - spec/lib/http/response/status_spec.rb
166
+ - spec/lib/http/response_spec.rb
167
+ - spec/lib/http_spec.rb
166
168
  - spec/spec_helper.rb
169
+ - spec/support/capture_warning.rb
167
170
  - spec/support/example_server.rb
168
171
  - spec/support/example_server/servlet.rb
169
172
  - spec/support/proxy_server.rb