http 0.9.9 → 1.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e30cb4fb424a8cc7177fef986701d40f763c79f1
4
- data.tar.gz: c591281ad736c5981881378c5f02aebe34d2770d
3
+ metadata.gz: a6a3c8891e4a8af6201fcda1333d5570ca5b0c15
4
+ data.tar.gz: e527a9a5e0976f1e9ef793fd451c127b76738607
5
5
  SHA512:
6
- metadata.gz: 9158b6f918b5bd8400fb1c5467058198e63b910b651bd5fc950e95f3481f84ba84c94a8e1e59f817185ff4b346e426bb3c4554eca1f22db8db5a5fff84c9b74d
7
- data.tar.gz: efb3e652ed99710318b3fff185db47bd99234a8f1777e6ff77029150b2c05fa422dd5da7ee0e1bc8c2132ba3a269626422d2b44290750c9d772ca0edb1ee8f36
6
+ metadata.gz: 4811c0bf41f037a2615f165d03ee1fd8dee7b42a4e743e1ec35638ca2ab96c82d9b808dfe96eff083003588b98c1dcc1502b8eb23c268e7ef239e388e27a00dc
7
+ data.tar.gz: 9e7357f1161890a87449b6c92040fff54d9b829481de267d85f0c9337e0ec8e9e3a6a13319ef6055875b09fd39d854f62a48179e1e248da1671c47bc609faf21
@@ -1,3 +1,4 @@
1
+ sudo: false
1
2
  bundler_args: --without development doc
2
3
  env:
3
4
  global:
data/CHANGES.md CHANGED
@@ -1,13 +1,18 @@
1
- ## 0.9.9 (2016-03-16)
2
-
3
- * *BACKPORT* [#318](https://github.com/httprb/http/pull/318)
4
- Remove redundant string allocations upon header names normalization.
5
- ([@ixti])
6
-
7
- * *BACKPORT* [#295](https://github.com/httprb/http/pull/295):
8
- Fix redirect following when used with persistent mode.
9
- ([@ixti])
10
-
1
+ ## 1.0.0.pre1 (2015-12-05)
2
+
3
+ * [#265](https://github.com/httprb/http/pull/265/):
4
+ Remove deprecations ([@tarcieri]):
5
+ - HTTP::Chainable#with_follow (use #follow)
6
+ - HTTP::Chainable#with, #with_headers (use #headers)
7
+ - HTTP::Chainable#auth(:basic, ...) (use #basic_auth)
8
+ - HTTP::Chainable#default_headers (use #default_options[:headers])
9
+ - HTTP::Headers#append (use #add)
10
+ - HTTP::Options#[] hash-like API deprecated in favor of explicit methods
11
+ - HTTP::Request#request_header (use #headline)
12
+ - HTTP::Response::STATUS_CODES (use HTTP::Status::REASONS)
13
+ - HTTP::Response::SYMBOL_TO_STATUS_CODE (no replacement)
14
+ - HTTP::Response#status_code (use #status or #code)
15
+ - HTTP::Response::Status#symbolize (use #to_sym)
11
16
 
12
17
  ## 0.9.8 (2015-09-29)
13
18
 
@@ -15,7 +20,6 @@
15
20
  Fixed global timeout persisting time left across requests when reusing connections.
16
21
  ([@zanker][])
17
22
 
18
-
19
23
  ## 0.9.7 (2015-09-19)
20
24
 
21
25
  * [#258](https://github.com/httprb/http/pull/258):
data/Gemfile CHANGED
@@ -20,11 +20,11 @@ end
20
20
  group :test do
21
21
  gem "backports"
22
22
  gem "coveralls"
23
- gem "simplecov", ">= 0.9"
24
- gem "json", ">= 1.8.1"
25
- gem "rspec", "~> 3.0"
23
+ gem "simplecov", ">= 0.9"
24
+ gem "json", ">= 1.8.1"
25
+ gem "rubocop", "= 0.35.1"
26
+ gem "rspec", "~> 3.0"
26
27
  gem "rspec-its"
27
- gem "rubocop"
28
28
  gem "yardstick"
29
29
  gem "certificate_authority"
30
30
  end
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Build Status](https://secure.travis-ci.org/httprb/http.svg?branch=master)](http://travis-ci.org/httprb/http)
5
5
  [![Code Climate](https://codeclimate.com/github/httprb/http.svg?branch=master)](https://codeclimate.com/github/httprb/http)
6
6
  [![Coverage Status](https://coveralls.io/repos/httprb/http/badge.svg?branch=master)](https://coveralls.io/r/httprb/http)
7
-
7
+ [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/httprb/http/blob/master/LICENSE.txt)
8
8
 
9
9
  ## About
10
10
 
@@ -276,30 +276,6 @@ HTTP.persistent('http://en.wikipedia.org') do |http|
276
276
  end
277
277
  ```
278
278
 
279
- ### Celluloid::IO Support
280
-
281
- http.rb makes it simple to make multiple concurrent HTTP requests from a
282
- Celluloid::IO actor. Here's a parallel HTTP fetcher combining http.rb with
283
- Celluloid::IO:
284
-
285
- ```ruby
286
- require "celluloid/io"
287
- require "http"
288
-
289
- class HttpFetcher
290
- include Celluloid::IO
291
-
292
- def fetch(url)
293
- HTTP.get(url, socket_class: Celluloid::IO::TCPSocket)
294
- end
295
- end
296
- ```
297
-
298
- There's a little more to it, but that's the core idea!
299
-
300
- * [Full parallel HTTP fetcher example](https://github.com/httprb/http/wiki/Parallel-requests-with-Celluloid%3A%3AIO)
301
- * See also: [Celluloid::IO](https://github.com/celluloid/celluloid-io)
302
-
303
279
  ### Timeouts
304
280
 
305
281
  By default, HTTP does not timeout on a request. You can enable per operation
@@ -83,7 +83,10 @@ module HTTP
83
83
  # @option options [Float] :write Write timeout
84
84
  # @option options [Float] :connect Connect timeout
85
85
  def timeout(klass, options = {})
86
- klass, options = :per_operation, klass if klass.is_a? Hash
86
+ if klass.is_a? Hash
87
+ options = klass
88
+ klass = :per_operation
89
+ end
87
90
 
88
91
  klass = case klass.to_sym
89
92
  when :null then HTTP::Timeout::Null
@@ -166,24 +169,12 @@ module HTTP
166
169
  branch default_options.with_follow opts
167
170
  end
168
171
 
169
- # @deprecated will be removed in 1.0.0
170
- # @see #follow
171
- alias_method :with_follow, :follow
172
-
173
172
  # Make a request with the given headers
174
173
  # @param headers
175
174
  def headers(headers)
176
175
  branch default_options.with_headers(headers)
177
176
  end
178
177
 
179
- # @deprecated will be removed in 1.0.0
180
- # @see #headers
181
- alias_method :with, :headers
182
-
183
- # @deprecated will be removed in 1.0.0
184
- # @see #headers
185
- alias_method :with_headers, :headers
186
-
187
178
  # Make a request with the given cookies
188
179
  def cookies(cookies)
189
180
  branch default_options.with_cookies(cookies)
@@ -197,10 +188,7 @@ module HTTP
197
188
 
198
189
  # Make a request with the given Authorization header
199
190
  # @param [#to_s] value Authorization header value
200
- def auth(value, opts = nil)
201
- # shim for deprecated auth(:basic, opts).
202
- # will be removed in 0.8.0
203
- return basic_auth(opts) if :basic == value
191
+ def auth(value)
204
192
  headers Headers::AUTHORIZATION => value.to_s
205
193
  end
206
194
 
@@ -229,21 +217,6 @@ module HTTP
229
217
  @default_options = HTTP::Options.new(opts)
230
218
  end
231
219
 
232
- # @deprecated Will be removed in 1.0.0; Use `#default_options#headers`
233
- # Get headers of HTTP options
234
- def default_headers
235
- default_options.headers
236
- end
237
-
238
- # Set headers of HTTP options
239
- # @deprecated Will be removed in 1.0.0; Use `#headers`
240
- # @param headers
241
- def default_headers=(headers)
242
- @default_options = default_options.dup do |opts|
243
- opts.headers = headers
244
- end
245
- end
246
-
247
220
  private
248
221
 
249
222
  # :nodoc:
@@ -22,15 +22,15 @@ module HTTP
22
22
  # @param [HTTP::Options] options
23
23
  def initialize(req, options)
24
24
  @persistent = options.persistent?
25
- @keep_alive_timeout = options[:keep_alive_timeout].to_f
25
+ @keep_alive_timeout = options.keep_alive_timeout.to_f
26
26
  @pending_request = false
27
27
  @pending_response = false
28
28
  @failed_proxy_connect = false
29
29
 
30
30
  @parser = Response::Parser.new
31
31
 
32
- @socket = options[:timeout_class].new(options[:timeout_options])
33
- @socket.connect(options[:socket_class], req.socket_host, req.socket_port)
32
+ @socket = options.timeout_class.new(options.timeout_options)
33
+ @socket.connect(options.socket_class, req.socket_host, req.socket_port)
34
34
 
35
35
  send_proxy_connect_request(req)
36
36
  start_tls(req, options)
@@ -148,14 +148,14 @@ module HTTP
148
148
  def start_tls(req, options)
149
149
  return unless req.uri.https? && !failed_proxy_connect?
150
150
 
151
- ssl_context = options[:ssl_context]
151
+ ssl_context = options.ssl_context
152
152
 
153
153
  unless ssl_context
154
154
  ssl_context = OpenSSL::SSL::SSLContext.new
155
- ssl_context.set_params(options[:ssl] || {})
155
+ ssl_context.set_params(options.ssl || {})
156
156
  end
157
157
 
158
- @socket.start_tls(req.uri.host, options[:ssl_socket_class], ssl_context)
158
+ @socket.start_tls(req.uri.host, options.ssl_socket_class, ssl_context)
159
159
  end
160
160
 
161
161
  # Open tunnel through proxy
@@ -11,11 +11,11 @@ module HTTP
11
11
  include Enumerable
12
12
 
13
13
  # Matches HTTP header names when in "Canonical-Http-Format"
14
- CANONICAL_NAME_RE = /^[A-Z][a-z]*(?:-[A-Z][a-z]*)*$/
14
+ CANONICAL_HEADER = /^[A-Z][a-z]*(-[A-Z][a-z]*)*$/
15
15
 
16
16
  # Matches valid header field name according to RFC.
17
17
  # @see http://tools.ietf.org/html/rfc7230#section-3.2
18
- COMPLIANT_NAME_RE = /^[A-Za-z0-9!#\$%&'*+\-.^_`|~]+$/
18
+ HEADER_NAME_RE = /^[A-Za-z0-9!#\$%&'*+\-.^_`|~]+$/
19
19
 
20
20
  # Class constructor.
21
21
  def initialize
@@ -51,9 +51,6 @@ module HTTP
51
51
  Array(value).each { |v| @pile << [name, v.to_s] }
52
52
  end
53
53
 
54
- # @deprecated Will be removed in 1.0.0
55
- alias_method :append, :add
56
-
57
54
  # Returns list of header values if any.
58
55
  #
59
56
  # @return [Array<String>]
@@ -194,11 +191,10 @@ module HTTP
194
191
  # match {HEADER_NAME_RE}
195
192
  # @return [String] canonical HTTP header name
196
193
  def normalize_header(name)
197
- return name if name =~ CANONICAL_NAME_RE
198
-
199
- normalized = name.split(/[\-_]/).each(&:capitalize!).join("-")
194
+ normalized = name[CANONICAL_HEADER]
195
+ normalized ||= name.split(/[\-_]/).map(&:capitalize).join("-")
200
196
 
201
- return normalized if normalized =~ COMPLIANT_NAME_RE
197
+ return normalized if normalized =~ HEADER_NAME_RE
202
198
 
203
199
  fail InvalidHeaderNameError, "Invalid HTTP header field name: #{name.inspect}"
204
200
  end
@@ -91,15 +91,6 @@ module HTTP
91
91
  !persistent.nil?
92
92
  end
93
93
 
94
- # @deprecated
95
- def [](option)
96
- send(option)
97
- rescue
98
- warn "[DEPRECATED] `HTTP::Options#[:#{option}]` was deprecated. " \
99
- "Use `HTTP::Options##{option}` instead."
100
- nil
101
- end
102
-
103
94
  def merge(other)
104
95
  h1 = to_hash
105
96
  h2 = other.to_hash
@@ -119,7 +110,7 @@ module HTTP
119
110
  def to_hash
120
111
  hash_pairs = self.class.
121
112
  defined_options.
122
- flat_map { |opt_name| [opt_name, self[opt_name]] }
113
+ flat_map { |opt_name| [opt_name, send(opt_name)] }
123
114
  Hash[*hash_pairs]
124
115
  end
125
116
 
@@ -54,8 +54,6 @@ module HTTP
54
54
  fail TooManyRedirectsError if too_many_hops?
55
55
  fail EndlessRedirectError if endless_loop?
56
56
 
57
- @response.flush
58
-
59
57
  @request = redirect_to @response.headers[Headers::LOCATION]
60
58
  @response = yield @request
61
59
  end
@@ -126,9 +126,6 @@ module HTTP
126
126
  "#{verb.to_s.upcase} #{request_uri.omit :fragment} HTTP/#{version}"
127
127
  end
128
128
 
129
- # @deprecated Will be removed in 1.0.0
130
- alias_method :request_header, :headline
131
-
132
129
  # Compute HTTP request header SSL proxy connection
133
130
  def proxy_connect_header
134
131
  "CONNECT #{host}:#{port} HTTP/#{version}"
@@ -14,13 +14,6 @@ module HTTP
14
14
 
15
15
  include HTTP::Headers::Mixin
16
16
 
17
- # @deprecated Will be removed in 1.0.0
18
- # Use Status::REASONS
19
- STATUS_CODES = Status::REASONS
20
-
21
- # @deprecated Will be removed in 1.0.0
22
- SYMBOL_TO_STATUS_CODE = Hash[STATUS_CODES.map { |k, v| [v.downcase.gsub(/\s|-/, "_").to_sym, k] }].freeze
23
-
24
17
  # @return [Status]
25
18
  attr_reader :status
26
19
 
@@ -46,9 +39,6 @@ module HTTP
46
39
  # @return (see HTTP::Response::Status#code)
47
40
  def_delegator :status, :code
48
41
 
49
- # @deprecated Will be removed in 1.0.0
50
- alias_method :status_code, :code
51
-
52
42
  # @!method to_s
53
43
  # (see HTTP::Response::Body#to_s)
54
44
  def_delegator :body, :to_s
@@ -42,7 +42,8 @@ module HTTP
42
42
  end
43
43
 
44
44
  def chunk
45
- chunk, @chunk = @chunk, nil
45
+ chunk = @chunk
46
+ @chunk = nil
46
47
  chunk
47
48
  end
48
49
 
@@ -91,9 +91,6 @@ module HTTP
91
91
  SYMBOLS[code]
92
92
  end
93
93
 
94
- # @deprecated Will be removed in 1.0.0
95
- alias_method :symbolize, :to_sym
96
-
97
94
  # Printable version of HTTP Status, surrounded by quote marks,
98
95
  # with special characters escaped.
99
96
  #
@@ -1,3 +1,3 @@
1
1
  module HTTP
2
- VERSION = "0.9.9".freeze
2
+ VERSION = "1.0.0.pre1".freeze
3
3
  end
@@ -1,9 +1,8 @@
1
1
  RSpec.describe HTTP::Options do
2
2
  subject { described_class.new(:response => :body) }
3
3
 
4
- it "behaves like a Hash for reading" do
5
- expect(subject[:response]).to eq(:body)
6
- expect(subject[:nosuchone]).to be nil
4
+ it "has reader methods for attributes" do
5
+ expect(subject.response).to eq(:body)
7
6
  end
8
7
 
9
8
  it "coerces to a Hash" do
@@ -34,8 +34,8 @@ RSpec.describe HTTP::Response::Status do
34
34
  end
35
35
  end
36
36
 
37
- describe "#symbolize" do
38
- subject { described_class.new(code).symbolize }
37
+ describe "#to_sym" do
38
+ subject { described_class.new(code).to_sym }
39
39
 
40
40
  context "with unknown code" do
41
41
  let(:code) { 1024 }
@@ -201,12 +201,12 @@ RSpec.describe HTTP do
201
201
  describe ".auth" do
202
202
  it "sets Authorization header to the given value" do
203
203
  client = HTTP.auth "abc"
204
- expect(client.default_headers[:authorization]).to eq "abc"
204
+ expect(client.default_options.headers[:authorization]).to eq "abc"
205
205
  end
206
206
 
207
207
  it "accepts any #to_s object" do
208
208
  client = HTTP.auth double :to_s => "abc"
209
- expect(client.default_headers[:authorization]).to eq "abc"
209
+ expect(client.default_options.headers[:authorization]).to eq "abc"
210
210
  end
211
211
  end
212
212
 
@@ -225,7 +225,7 @@ RSpec.describe HTTP do
225
225
 
226
226
  it "sets Authorization header with proper BasicAuth value" do
227
227
  client = HTTP.basic_auth :user => "foo", :pass => "bar"
228
- expect(client.default_headers[:authorization]).
228
+ expect(client.default_options.headers[:authorization]).
229
229
  to match(%r{^Basic [A-Za-z0-9+/]+=*$})
230
230
  end
231
231
  end
@@ -93,6 +93,9 @@ RSpec.shared_context "HTTP handling" do
93
93
  let(:read_timeout) { 2.5 }
94
94
 
95
95
  it "does not timeout" do
96
+ # TODO: investigate sporadic JRuby timeouts on CI
97
+ skip if defined?(JRUBY_VERSION)
98
+
96
99
  client.get("#{server.endpoint}/sleep").body.to_s
97
100
  client.get("#{server.endpoint}/sleep").body.to_s
98
101
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
4
+ version: 1.0.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-03-16 00:00:00.000000000 Z
14
+ date: 2015-12-05 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: http_parser.rb
@@ -179,12 +179,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
179
  version: '0'
180
180
  required_rubygems_version: !ruby/object:Gem::Requirement
181
181
  requirements:
182
- - - ">="
182
+ - - ">"
183
183
  - !ruby/object:Gem::Version
184
- version: '0'
184
+ version: 1.3.1
185
185
  requirements: []
186
186
  rubyforge_project:
187
- rubygems_version: 2.2.5
187
+ rubygems_version: 2.4.8
188
188
  signing_key:
189
189
  specification_version: 4
190
190
  summary: HTTP should be easy