http 5.0.2 → 5.0.3

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
  SHA256:
3
- metadata.gz: fe455ddc7caea6475216135d2748825078dfe40aa5d474e219e054a330d54967
4
- data.tar.gz: cdc04d4ccd9e7a8d45ad5db093c63bd2172720aa0c22f6e095fe93c6892e4ea2
3
+ metadata.gz: 07b34c228e87205e026b3e446bb870391df41188fa7d97438c863825819a6694
4
+ data.tar.gz: 4892ec252ec9f4fff897bd3860af14b6379fc97363f916b225d337dd000af343
5
5
  SHA512:
6
- metadata.gz: eff3f4e56087fd798ecc435ddc662b9e3b8e248c4a39448323643238cc7f8855a98ecfbe392e26f9e77b9129f18fcab13c1a3c588c819453a2f5199a24683c28
7
- data.tar.gz: fe8fbd07014f69631414e2644aa48198e34cac0d085a4bce8f056a5284088a2414557a5bb83456f953ce2fdaa6b69621746a31430446664f56eca2a2b454117c
6
+ metadata.gz: 4b3f3261bf7215369f88c06a2147eeb0b1811aeb76aba86b59c2def09cdbc8e5b5b53197f4124af9de032a11e8786060957cb684dc03c52c35425e5f967b1ac8
7
+ data.tar.gz: 7dc0afcf98bbe98da6c769e9d5eb30dd84a82e9095e3191840f3063099317fe37559c8e09282ff56c0cf39e77f70179e6605651c196198b1c8f4a49cf6b8a851
data/CHANGES.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 5.0.3 (2021-10-06)
2
+
3
+ * [#695](https://github.com/httprb/http/pull/695)
4
+ Revert DNS resolving feature.
5
+ ([@PhilCoggins])
6
+
7
+ * [#694](https://github.com/httprb/http/pull/694)
8
+ Fix cookies extraction.
9
+ ([@flosacca])
10
+
1
11
  ## 5.0.2 (2021-09-10)
2
12
 
3
13
  * [#686](https://github.com/httprb/http/pull/686)
@@ -28,6 +38,7 @@
28
38
  DNS failover handling.
29
39
  ([@midnight-wonderer])
30
40
 
41
+
31
42
  ## 5.0.1 (2021-06-26)
32
43
 
33
44
  * [#670](https://github.com/httprb/http/pull/670)
@@ -42,6 +53,7 @@
42
53
  Bump llhttp-ffi to 0.3.0.
43
54
  ([@bryanp])
44
55
 
56
+
45
57
  ## 5.0.0 (2021-05-12)
46
58
 
47
59
  * [#656](https://github.com/httprb/http/pull/656)
@@ -948,3 +960,5 @@ end
948
960
  [@midnight-wonderer]: https://github.com/midnight-wonderer
949
961
  [@schwern]: https://github.com/schwern
950
962
  [@matheussilvasantos]: https://github.com/matheussilvasantos
963
+ [@PhilCoggins]: https://github.com/PhilCoggins
964
+ [@flosacca]: https://github.com/flosacca
data/Gemfile CHANGED
@@ -27,7 +27,7 @@ group :test do
27
27
 
28
28
  gem "backports"
29
29
 
30
- gem "rubocop"
30
+ gem "rubocop", "~> 1.21"
31
31
  gem "rubocop-performance"
32
32
  gem "rubocop-rake"
33
33
  gem "rubocop-rspec"
data/README.md CHANGED
@@ -1,16 +1,12 @@
1
- # ![http.rb](https://raw.github.com/httprb/http.rb/master/logo.png)
1
+ # ![http.rb](https://raw.github.com/httprb/http.rb/main/logo.png)
2
2
 
3
- [![Gem Version](https://img.shields.io/gem/v/http?logo=ruby)](https://rubygems.org/gems/http)
4
- [![Build Status](https://github.com/httprb/http/workflows/CI/badge.svg)](https://github.com/httprb/http/actions?query=workflow:CI)
5
- [![Code Climate](https://codeclimate.com/github/httprb/http.svg?branch=master)](https://codeclimate.com/github/httprb/http)
6
- [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/httprb/http/blob/master/LICENSE.txt)
3
+ [![Gem Version][gem-image]][gem-link]
4
+ [![MIT licensed][license-image]][license-link]
5
+ [![Build Status][build-image]][build-link]
6
+ [![Code Climate][codeclimate-image]][codeclimate-link]
7
7
 
8
8
  [Documentation]
9
9
 
10
- _NOTE: This is the 5.x **development** branch. For the 4.x **stable** branch, please see:_
11
-
12
- https://github.com/httprb/http/tree/4-x-stable
13
-
14
10
  ## About
15
11
 
16
12
  HTTP (The Gem! a.k.a. http.rb) is an easy-to-use client library for making requests
@@ -21,63 +17,16 @@ Under the hood, http.rb uses the [llhttp] parser, a fast HTTP parsing native ext
21
17
  This library isn't just yet another wrapper around `Net::HTTP`. It implements the HTTP
22
18
  protocol natively and outsources the parsing to native extensions.
23
19
 
24
- [requests]: http://docs.python-requests.org/en/latest/
25
- [llhttp]: https://llhttp.org/
26
-
27
-
28
- ## Another Ruby HTTP library? Why should I care?
29
-
30
- There are a lot of HTTP libraries to choose from in the Ruby ecosystem.
31
- So why would you choose this one?
20
+ ### Why http.rb?
32
21
 
33
- Top three reasons:
34
-
35
- 1. **Clean API**: http.rb offers an easy-to-use API that should be a
22
+ - **Clean API**: http.rb offers an easy-to-use API that should be a
36
23
  breath of fresh air after using something like Net::HTTP.
37
24
 
38
- 2. **Maturity**: http.rb is one of the most mature Ruby HTTP clients, supporting
25
+ - **Maturity**: http.rb is one of the most mature Ruby HTTP clients, supporting
39
26
  features like persistent connections and fine-grained timeouts.
40
27
 
41
- 3. **Performance**: using native parsers and a clean, lightweight implementation,
42
- http.rb achieves the best performance of any Ruby HTTP library which
43
- implements the HTTP protocol in Ruby instead of C:
44
-
45
- | HTTP client | Time | Implementation |
46
- |--------------------------|--------|-----------------------|
47
- | curb (persistent) | 2.519 | libcurl wrapper |
48
- | em-http-request | 2.731 | EM + http_parser.rb |
49
- | Typhoeus | 2.851 | libcurl wrapper |
50
- | StreamlyFFI (persistent) | 2.853 | libcurl wrapper |
51
- | http.rb (persistent) | 2.970 | Ruby + http_parser.rb |
52
- | http.rb | 3.588 | Ruby + http_parser.rb |
53
- | HTTParty | 3.931 | Net::HTTP wrapper |
54
- | Net::HTTP | 3.959 | Pure Ruby |
55
- | Net::HTTP (persistent) | 4.043 | Pure Ruby |
56
- | open-uri | 4.479 | Net::HTTP wrapper |
57
- | Excon (persistent) | 4.618 | Pure Ruby |
58
- | Excon | 4.701 | Pure Ruby |
59
- | RestClient | 26.838 | Net::HTTP wrapper |
60
-
61
- Benchmarks performed using excon's benchmarking tool
62
-
63
- DISCLAIMER: Most benchmarks you find in READMEs are crap,
64
- including this one. These are out-of-date. If you care about
65
- performance, benchmark for yourself for your own use cases!
66
-
67
- ## Help and Discussion
68
-
69
- If you need help or just want to talk about the http.rb,
70
- visit the http.rb Google Group:
71
-
72
- https://groups.google.com/forum/#!forum/httprb
73
-
74
- You can join by email by sending a message to:
75
-
76
- [httprb+subscribe@googlegroups.com](mailto:httprb+subscribe@googlegroups.com)
77
-
78
- If you believe you've found a bug, please report it at:
79
-
80
- https://github.com/httprb/http/issues
28
+ - **Performance**: using native parsers and a clean, lightweight implementation,
29
+ http.rb achieves high performance while implementing HTTP in Ruby instead of C.
81
30
 
82
31
 
83
32
  ## Installation
@@ -112,10 +61,9 @@ for more detailed documentation and usage notes.
112
61
 
113
62
  The following API documentation is also available:
114
63
 
115
- * [YARD API documentation](https://www.rubydoc.info/github/httprb/http)
116
- * [Chainable module (all chainable methods)](https://www.rubydoc.info/github/httprb/http/HTTP/Chainable)
64
+ - [YARD API documentation](https://www.rubydoc.info/github/httprb/http)
65
+ - [Chainable module (all chainable methods)](https://www.rubydoc.info/github/httprb/http/HTTP/Chainable)
117
66
 
118
- [documentation]: https://github.com/httprb/http/wiki
119
67
 
120
68
  ### Basic Usage
121
69
 
@@ -142,7 +90,7 @@ We can also obtain an `HTTP::Response::Body` object for this response:
142
90
  ```
143
91
 
144
92
  The response body can be streamed with `HTTP::Response::Body#readpartial`.
145
- In practice, you'll want to bind the HTTP::Response::Body to a local variable
93
+ In practice, you'll want to bind the `HTTP::Response::Body` to a local variable
146
94
  and call `#readpartial` on it repeatedly until it returns `nil`:
147
95
 
148
96
  ```ruby
@@ -159,13 +107,13 @@ and call `#readpartial` on it repeatedly until it returns `nil`:
159
107
 
160
108
  ## Supported Ruby Versions
161
109
 
162
- This library aims to support and is [tested against][travis] the following Ruby
163
- versions:
110
+ This library aims to support and is [tested against][build-link]
111
+ the following Ruby versions:
164
112
 
165
- * Ruby 2.6
166
- * Ruby 2.7
167
- * Ruby 3.0
168
- * JRuby 9.2
113
+ - Ruby 2.6
114
+ - Ruby 2.7
115
+ - Ruby 3.0
116
+ - JRuby 9.2
169
117
 
170
118
  If something doesn't work on one of these versions, it's a bug.
171
119
 
@@ -180,20 +128,36 @@ patches in a timely fashion. If critical issues for a particular implementation
180
128
  exist at the time of a major release, support for that Ruby version may be
181
129
  dropped.
182
130
 
183
- [travis]: http://travis-ci.org/httprb/http
184
-
185
131
 
186
132
  ## Contributing to http.rb
187
133
 
188
- * Fork http.rb on GitHub
189
- * Make your changes
190
- * Ensure all tests pass (`bundle exec rake`)
191
- * Send a pull request
192
- * If we like them we'll merge them
193
- * If we've accepted a patch, feel free to ask for commit access!
134
+ - Fork http.rb on GitHub
135
+ - Make your changes
136
+ - Ensure all tests pass (`bundle exec rake`)
137
+ - Send a pull request
138
+ - If we like them we'll merge them
139
+ - If we've accepted a patch, feel free to ask for commit access!
194
140
 
195
141
 
196
142
  ## Copyright
197
143
 
198
- Copyright (c) 2011-2021 Tony Arcieri, Alexey V. Zapparov, Erik Michaels-Ober, Zachary Anker.
144
+ Copyright © 2011-2021 Tony Arcieri, Alexey V. Zapparov, Erik Michaels-Ober, Zachary Anker.
199
145
  See LICENSE.txt for further details.
146
+
147
+
148
+ [//]: # (badges)
149
+
150
+ [gem-image]: https://img.shields.io/gem/v/http?logo=ruby
151
+ [gem-link]: https://rubygems.org/gems/http
152
+ [license-image]: https://img.shields.io/badge/license-MIT-blue.svg
153
+ [license-link]: https://github.com/httprb/http/blob/main/LICENSE.txt
154
+ [build-image]: https://github.com/httprb/http/workflows/CI/badge.svg
155
+ [build-link]: https://github.com/httprb/http/actions/workflows/ci.yml
156
+ [codeclimate-image]: https://codeclimate.com/github/httprb/http.svg?branch=main
157
+ [codeclimate-link]: https://codeclimate.com/github/httprb/http
158
+
159
+ [//]: # (links)
160
+
161
+ [documentation]: https://github.com/httprb/http/wiki
162
+ [requests]: http://docs.python-requests.org/en/latest/
163
+ [llhttp]: https://llhttp.org/
@@ -61,7 +61,7 @@ module HTTP
61
61
  def join_headers
62
62
  # join the headers array with crlfs, stick two on the end because
63
63
  # that ends the request header
64
- @request_header.join(CRLF) + CRLF * 2
64
+ @request_header.join(CRLF) + (CRLF * 2)
65
65
  end
66
66
 
67
67
  # Writes HTTP request data into the socket.
data/lib/http/response.rb CHANGED
@@ -138,8 +138,8 @@ module HTTP
138
138
  def_delegator :content_type, :charset
139
139
 
140
140
  def cookies
141
- @cookies ||= headers.each_with_object CookieJar.new do |(k, v), jar|
142
- jar.parse(v, uri) if k == Headers::SET_COOKIE
141
+ @cookies ||= headers.get(Headers::SET_COOKIE).each_with_object CookieJar.new do |v, jar|
142
+ jar.parse(v, uri)
143
143
  end
144
144
  end
145
145
 
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "io/wait"
4
- require "resolv"
5
3
  require "timeout"
4
+ require "io/wait"
6
5
 
7
6
  require "http/timeout/null"
8
7
 
@@ -13,9 +12,6 @@ module HTTP
13
12
  super
14
13
 
15
14
  @timeout = @time_left = options.fetch(:global_timeout)
16
- @dns_resolver = options.fetch(:dns_resolver) do
17
- ::Resolv.method(:getaddresses)
18
- end
19
15
  end
20
16
 
21
17
  # To future me: Don't remove this again, past you was smarter.
@@ -23,28 +19,14 @@ module HTTP
23
19
  @time_left = @timeout
24
20
  end
25
21
 
26
- def connect(socket_class, host_name, *args)
27
- connect_operation = lambda do |host_address|
28
- ::Timeout.timeout(@time_left, TimeoutError) do
29
- super(socket_class, host_address, *args)
30
- end
31
- end
32
- host_addresses = @dns_resolver.call(host_name)
33
- # ensure something to iterates
34
- trying_targets = host_addresses.empty? ? [host_name] : host_addresses
22
+ def connect(socket_class, host, port, nodelay = false)
35
23
  reset_timer
36
- trying_iterator = trying_targets.lazy
37
- error = nil
38
- begin
39
- connect_operation.call(trying_iterator.next).tap do
40
- log_time
41
- end
42
- rescue TimeoutError => e
43
- error = e
44
- retry
45
- rescue ::StopIteration
46
- raise error
24
+ ::Timeout.timeout(@time_left, TimeoutError) do
25
+ @socket = socket_class.open(host, port)
26
+ @socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) if nodelay
47
27
  end
28
+
29
+ log_time
48
30
  end
49
31
 
50
32
  def connect_ssl
@@ -53,11 +35,11 @@ module HTTP
53
35
  begin
54
36
  @socket.connect_nonblock
55
37
  rescue IO::WaitReadable
56
- IO.select([@socket], nil, nil, @time_left)
38
+ @socket.wait_readable(@time_left)
57
39
  log_time
58
40
  retry
59
41
  rescue IO::WaitWritable
60
- IO.select(nil, [@socket], nil, @time_left)
42
+ @socket.wait_writable(@time_left)
61
43
  log_time
62
44
  retry
63
45
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "resolv"
4
3
  require "timeout"
5
4
 
6
5
  require "http/timeout/null"
@@ -18,34 +17,14 @@ module HTTP
18
17
  @read_timeout = options.fetch(:read_timeout, READ_TIMEOUT)
19
18
  @write_timeout = options.fetch(:write_timeout, WRITE_TIMEOUT)
20
19
  @connect_timeout = options.fetch(:connect_timeout, CONNECT_TIMEOUT)
21
- @dns_resolver = options.fetch(:dns_resolver) do
22
- ::Resolv.method(:getaddresses)
23
- end
24
20
  end
25
21
 
26
- # TODO: refactor
27
- # rubocop:disable Metrics/MethodLength
28
- def connect(socket_class, host_name, *args)
29
- connect_operation = lambda do |host_address|
30
- ::Timeout.timeout(@connect_timeout, TimeoutError) do
31
- super(socket_class, host_address, *args)
32
- end
33
- end
34
- host_addresses = @dns_resolver.call(host_name)
35
- # ensure something to iterates
36
- trying_targets = host_addresses.empty? ? [host_name] : host_addresses
37
- trying_iterator = trying_targets.lazy
38
- error = nil
39
- begin
40
- connect_operation.call(trying_iterator.next)
41
- rescue TimeoutError => e
42
- error = e
43
- retry
44
- rescue ::StopIteration
45
- raise error
22
+ def connect(socket_class, host, port, nodelay = false)
23
+ ::Timeout.timeout(@connect_timeout, TimeoutError) do
24
+ @socket = socket_class.open(host, port)
25
+ @socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) if nodelay
46
26
  end
47
27
  end
48
- # rubocop:enable Metrics/MethodLength
49
28
 
50
29
  def connect_ssl
51
30
  rescue_readable(@connect_timeout) do
data/lib/http/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTP
4
- VERSION = "5.0.2"
4
+ VERSION = "5.0.3"
5
5
  end
@@ -118,10 +118,10 @@ RSpec.describe HTTP::Request::Body do
118
118
  end
119
119
 
120
120
  context "when body is a non-Enumerable IO" do
121
- let(:body) { FakeIO.new("a" * 16 * 1024 + "b" * 10 * 1024) }
121
+ let(:body) { FakeIO.new(("a" * 16 * 1024) + ("b" * 10 * 1024)) }
122
122
 
123
123
  it "yields chunks of content" do
124
- expect(chunks.inject("", :+)).to eq "a" * 16 * 1024 + "b" * 10 * 1024
124
+ expect(chunks.inject("", :+)).to eq ("a" * 16 * 1024) + ("b" * 10 * 1024)
125
125
  end
126
126
  end
127
127
 
@@ -148,7 +148,7 @@ RSpec.describe HTTP::Request::Body do
148
148
  end
149
149
 
150
150
  context "when body is an Enumerable IO" do
151
- let(:data) { "a" * 16 * 1024 + "b" * 10 * 1024 }
151
+ let(:data) { ("a" * 16 * 1024) + ("b" * 10 * 1024) }
152
152
  let(:body) { StringIO.new data }
153
153
 
154
154
  it "yields chunks of content" do
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: 5.0.2
4
+ version: 5.0.3
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: 2021-09-10 00:00:00.000000000 Z
14
+ date: 2021-10-06 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: addressable
@@ -191,7 +191,7 @@ metadata:
191
191
  source_code_uri: https://github.com/httprb/http
192
192
  wiki_uri: https://github.com/httprb/http/wiki
193
193
  bug_tracker_uri: https://github.com/httprb/http/issues
194
- changelog_uri: https://github.com/httprb/http/blob/v5.0.2/CHANGES.md
194
+ changelog_uri: https://github.com/httprb/http/blob/v5.0.3/CHANGES.md
195
195
  post_install_message:
196
196
  rdoc_options: []
197
197
  require_paths: