httpx 0.8.2 → 0.9.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44d4a0720ab5167dbff45524a71c6950d271a82532e09ce3b3e01f0d348b3e55
4
- data.tar.gz: 02cc85986aeb4290c62977b2388567990cf023fa1675d559fc8fbb597db2c434
3
+ metadata.gz: e15b3e81842118829ecc251093ce5e80ad0c82dada2c7b2588004b2bf7313f63
4
+ data.tar.gz: 9d4efcb47f0c269f2c5b9a3c950fe8069c3b76ffb2f9624b557d29a702704712
5
5
  SHA512:
6
- metadata.gz: 661fc0f5198c045779823ef3c256fad4cb19a84ac44c0e99eee2bb842809ad6cc4558b5ec2bb1b827a44b0c960daa07759d1b21466312527efe5bde1420af391
7
- data.tar.gz: fe40c074d0ff47ca8dc7781272c836423c0f254b0b70c4a08f35b1d25d00ba58ba7906fb49d0848e5624f5cf91b6a94cdb3abb9a08ffdc459fa9c7cb81be802f
6
+ metadata.gz: 9fbd146e351da8f603c8b00c236d92c7a2a3c383296736f271c88b0ac310086adf0127af7b630e9087ec45c4a22494128b2efafdb2592de43df4aae4a68ef1f3
7
+ data.tar.gz: eecb817b76bc0f217b728c7e862f73758e4b2db9c6a943311e0c7d10d8e7fe6bfa8e56a7c0d4593158fb605927813a1e720ec85a9d7e70aae8ecce015f5da647
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/httpx.svg)](http://rubygems.org/gems/httpx)
4
4
  [![pipeline status](https://gitlab.com/honeyryderchuck/httpx/badges/master/pipeline.svg)](https://gitlab.com/honeyryderchuck/httpx/commits/master)
5
- [![coverage report](https://gitlab.com/honeyryderchuck/httpx/badges/master/coverage.svg)](https://honeyryderchuck.gitlab.io/httpx/coverage/#_AllFiles)
5
+ [![coverage report](https://gitlab.com/honeyryderchuck/httpx/badges/master/coverage.svg?job=coverage)](https://honeyryderchuck.gitlab.io/httpx/coverage/#_AllFiles)
6
6
 
7
7
  HTTPX is an HTTP client library for the Ruby programming language.
8
8
 
@@ -0,0 +1,38 @@
1
+ # 0.9.0
2
+
3
+ ## Features
4
+
5
+ ### Multiple requests with specific options
6
+
7
+ You can now pass a third element to the "request element" of an array to `.request`.
8
+
9
+ ```ruby
10
+ requests = [
11
+ [:post, "https://url/post", { form: { foo: "bar" } }],
12
+ [:post, "https://url/post", { form: { foo: "bar2" } }]
13
+ ]
14
+ HTTPX.request(requests)
15
+ # or, if you want to pass options common to all requests
16
+ HTTPX.request(requests, max_concurrent_requests: 1)
17
+ ```
18
+
19
+
20
+ ### HTTPX::Session#build_request
21
+
22
+ `HTTPX::Session::build_request` is now public API from a session. You can now build requests before you send them. These request objects are still considered somewhat "internal", so consider them immutable and **do not rely on its API**. Just pass them forward.
23
+
24
+ Note: this API is only available for instantiated session, so there is no `HTTPX.build_request`.
25
+
26
+
27
+ ```ruby
28
+
29
+ HTTPX.wrap do |http|
30
+ requests = [
31
+ http.build_request(:post, "https://url/post", { form: { foo: "bar" } }),
32
+ http.build_request(:post, "https://url/post", { form: { foo: "bar2" } })
33
+ ]
34
+ http.request(requests)
35
+ # or, if you want to pass options common to all requests
36
+ http.request(requests, max_concurrent_requests: 1)
37
+ end
38
+ ```
@@ -10,8 +10,8 @@ module HTTPX
10
10
  MOD
11
11
  end
12
12
 
13
- def request(verb, uri, **options)
14
- branch(default_options).request(verb, uri, **options)
13
+ def request(*args, **options)
14
+ branch(default_options).request(*args, **options)
15
15
  end
16
16
 
17
17
  # :nocov:
@@ -59,7 +59,6 @@ module HTTPX
59
59
  @options || Options.new
60
60
  end
61
61
 
62
- # :nodoc:
63
62
  def branch(options, &blk)
64
63
  return self.class.new(options, &blk) if is_a?(Session)
65
64
 
@@ -11,7 +11,7 @@ module HTTPX
11
11
  #
12
12
  # Why not using Refinements? Because they don't work for Method (tested with ruby 2.1.9).
13
13
  #
14
- module CurryMethods # :nodoc:
14
+ module CurryMethods
15
15
  # Backport for the Method#curry method, which is part of ruby core since 2.2 .
16
16
  #
17
17
  def curry(*args)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module HTTPX
4
4
  class Headers
5
- EMPTY = [].freeze # :nodoc:
5
+ EMPTY = [].freeze
6
6
 
7
7
  class << self
8
8
  def new(headers = nil)
@@ -146,8 +146,10 @@ module HTTPX
146
146
  end
147
147
 
148
148
  def merge(other)
149
- h1 = to_hash
150
149
  h2 = other.to_hash
150
+ return self if h2.empty?
151
+
152
+ h1 = to_hash
151
153
 
152
154
  merged = h1.merge(h2) do |k, v1, v2|
153
155
  case k
@@ -239,13 +239,11 @@ module HTTPX
239
239
 
240
240
  private
241
241
 
242
- # :nodoc:
243
242
  def mime_type(str)
244
243
  m = str.to_s[MIME_TYPE_RE, 1]
245
244
  m && m.strip.downcase
246
245
  end
247
246
 
248
- # :nodoc:
249
247
  def charset(str)
250
248
  m = str.to_s[CHARSET_RE, 1]
251
249
  m && m.strip.delete('"')
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "io/wait"
4
4
 
5
- module IOExtensions # :nodoc:
5
+ module IOExtensions
6
6
  refine IO do
7
7
  def wait(timeout = nil, mode = :read)
8
8
  case mode
@@ -5,7 +5,9 @@ module HTTPX
5
5
  include Loggable
6
6
  include Chainable
7
7
 
8
- def initialize(options = {}, &blk)
8
+ EMPTY_HASH = {}.freeze
9
+
10
+ def initialize(options = EMPTY_HASH, &blk)
9
11
  @options = self.class.default_options.merge(options)
10
12
  @responses = {}
11
13
  @persistent = @options.persistent
@@ -29,13 +31,21 @@ module HTTPX
29
31
  end
30
32
 
31
33
  def request(*args, **options)
32
- requests = build_requests(*args, options)
34
+ requests = args.first.is_a?(Request) ? args : build_requests(*args, options)
33
35
  responses = send_requests(*requests, options)
34
36
  return responses.first if responses.size == 1
35
37
 
36
38
  responses
37
39
  end
38
40
 
41
+ def build_request(verb, uri, options = EMPTY_HASH)
42
+ rklass = @options.request_class
43
+ request = rklass.new(verb, uri, @options.merge(options).merge(persistent: @persistent))
44
+ request.on(:response, &method(:on_response).curry[request])
45
+ request.on(:promise, &method(:on_promise))
46
+ request
47
+ end
48
+
39
49
  private
40
50
 
41
51
  def pool
@@ -122,8 +132,8 @@ module HTTPX
122
132
  requests = case args.size
123
133
  when 1
124
134
  reqs = args.first
125
- reqs.map do |verb, uri|
126
- build_request(verb, uri, request_options)
135
+ reqs.map do |verb, uri, opts = EMPTY_HASH|
136
+ build_request(verb, uri, request_options.merge(opts))
127
137
  end
128
138
  when 2, 3
129
139
  verb, uris = args
@@ -195,14 +205,6 @@ module HTTPX
195
205
  end
196
206
  end
197
207
 
198
- def build_request(verb, uri, options)
199
- rklass = @options.request_class
200
- request = rklass.new(verb, uri, @options.merge(options).merge(persistent: @persistent))
201
- request.on(:response, &method(:on_response).curry[request])
202
- request.on(:promise, &method(:on_promise))
203
- request
204
- end
205
-
206
208
  @default_options = Options.new
207
209
  @default_options.freeze
208
210
  @plugins = []
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTPX
4
- VERSION = "0.8.2"
4
+ VERSION = "0.9.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Cardoso
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-06 00:00:00.000000000 Z
11
+ date: 2020-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-2-next
@@ -90,6 +90,7 @@ extra_rdoc_files:
90
90
  - doc/release_notes/0_6_0.md
91
91
  - doc/release_notes/0_8_2.md
92
92
  - doc/release_notes/0_6_4.md
93
+ - doc/release_notes/0_9_0.md
93
94
  - doc/release_notes/0_6_3.md
94
95
  - doc/release_notes/0_8_1.md
95
96
  - doc/release_notes/0_5_0.md
@@ -135,6 +136,7 @@ files:
135
136
  - doc/release_notes/0_8_0.md
136
137
  - doc/release_notes/0_8_1.md
137
138
  - doc/release_notes/0_8_2.md
139
+ - doc/release_notes/0_9_0.md
138
140
  - lib/httpx.rb
139
141
  - lib/httpx/adapters/faraday.rb
140
142
  - lib/httpx/altsvc.rb
@@ -203,7 +205,7 @@ metadata:
203
205
  changelog_uri: https://honeyryderchuck.gitlab.io/httpx/#release-notes
204
206
  documentation_uri: https://honeyryderchuck.gitlab.io/httpx/rdoc/
205
207
  source_code_uri: https://gitlab.com/honeyryderchuck/httpx
206
- post_install_message:
208
+ post_install_message:
207
209
  rdoc_options: []
208
210
  require_paths:
209
211
  - lib
@@ -219,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
221
  version: '0'
220
222
  requirements: []
221
223
  rubygems_version: 3.1.2
222
- signing_key:
224
+ signing_key:
223
225
  specification_version: 4
224
226
  summary: HTTPX, to the future, and beyond
225
227
  test_files: []