httpx 0.5.0 → 0.5.1
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 +4 -4
- data/lib/httpx/buffer.rb +4 -2
- data/lib/httpx/connection/http2.rb +2 -2
- data/lib/httpx/headers.rb +9 -0
- data/lib/httpx/io/tcp.rb +2 -2
- data/lib/httpx/io/udp.rb +1 -1
- data/lib/httpx/options.rb +11 -1
- data/lib/httpx/parser/http1.rb +4 -2
- data/lib/httpx/plugins/compression.rb +23 -1
- data/lib/httpx/plugins/cookies.rb +4 -0
- data/lib/httpx/transcoder/chunker.rb +7 -4
- data/lib/httpx/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d46b9e4e151ec41d27edd3c5890081bd08f8d1106e12ed7be49432fba952e2e
|
4
|
+
data.tar.gz: b4db1fe32bf9e97171c08f8e2477adfd84b56c50d1d76f34144d7b6bc281473c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfa30d6432aa328391d19e4a236c962232a216d049d8b5aa5a41ae5d35f0a796b88603de96225ed88d23ed8408af355e8edaed5f07c183b50978b4f6d8570a60
|
7
|
+
data.tar.gz: e3186c27ab01a92653bb72fbd628f8b5d2738e90050d0873cac0e94767a374ba1f6bb0735a0b7391ff2343f5f53c0b1642ec8b55b77cc3c9936548065723be2a
|
data/lib/httpx/buffer.rb
CHANGED
@@ -16,8 +16,6 @@ module HTTPX
|
|
16
16
|
|
17
17
|
def_delegator :@buffer, :bytesize
|
18
18
|
|
19
|
-
def_delegator :@buffer, :slice!
|
20
|
-
|
21
19
|
def_delegator :@buffer, :clear
|
22
20
|
|
23
21
|
def_delegator :@buffer, :replace
|
@@ -32,5 +30,9 @@ module HTTPX
|
|
32
30
|
def full?
|
33
31
|
@buffer.bytesize >= @limit
|
34
32
|
end
|
33
|
+
|
34
|
+
def shift!(fin)
|
35
|
+
@buffer = @buffer.byteslice(fin..-1)
|
36
|
+
end
|
35
37
|
end
|
36
38
|
end
|
@@ -198,7 +198,7 @@ module HTTPX
|
|
198
198
|
def on_stream_close(stream, request, error)
|
199
199
|
return handle(request, stream) if request.expects?
|
200
200
|
|
201
|
-
if error
|
201
|
+
if error && error != :no_error
|
202
202
|
ex = Error.new(stream.id, error)
|
203
203
|
ex.set_backtrace(caller)
|
204
204
|
emit(:error, request, ex)
|
@@ -230,7 +230,7 @@ module HTTPX
|
|
230
230
|
end
|
231
231
|
|
232
232
|
def on_close(_last_frame, error, _payload)
|
233
|
-
if error
|
233
|
+
if error && error != :no_error
|
234
234
|
ex = Error.new(0, error)
|
235
235
|
ex.set_backtrace(caller)
|
236
236
|
@streams.each_key do |request|
|
data/lib/httpx/headers.rb
CHANGED
@@ -41,6 +41,15 @@ module HTTPX
|
|
41
41
|
super
|
42
42
|
end
|
43
43
|
|
44
|
+
def same_headers?(headers)
|
45
|
+
@headers.empty? || begin
|
46
|
+
headers.each do |k, v|
|
47
|
+
return false unless v == self[k]
|
48
|
+
end
|
49
|
+
true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
44
53
|
# merges headers with another header-quack.
|
45
54
|
# the merge rule is, if the header already exists,
|
46
55
|
# ignore what the +other+ headers has. Otherwise, set
|
data/lib/httpx/io/tcp.rb
CHANGED
@@ -87,7 +87,7 @@ module HTTPX
|
|
87
87
|
|
88
88
|
def write(buffer)
|
89
89
|
siz = @io.write_nonblock(buffer)
|
90
|
-
buffer.
|
90
|
+
buffer.shift!(siz)
|
91
91
|
siz
|
92
92
|
rescue ::IO::WaitWritable
|
93
93
|
0
|
@@ -108,7 +108,7 @@ module HTTPX
|
|
108
108
|
return 0 if siz == :wait_writable
|
109
109
|
return if siz.nil?
|
110
110
|
|
111
|
-
buffer.
|
111
|
+
buffer.shift!(siz)
|
112
112
|
siz
|
113
113
|
end
|
114
114
|
end
|
data/lib/httpx/io/udp.rb
CHANGED
data/lib/httpx/options.rb
CHANGED
@@ -108,10 +108,20 @@ module HTTPX
|
|
108
108
|
def_option(method_name)
|
109
109
|
end
|
110
110
|
|
111
|
+
REQUEST_IVARS = %i[@params @form @json @body].freeze
|
112
|
+
|
111
113
|
def ==(other)
|
112
114
|
ivars = instance_variables | other.instance_variables
|
113
115
|
ivars.all? do |ivar|
|
114
|
-
|
116
|
+
case ivar
|
117
|
+
when :@headers
|
118
|
+
headers = instance_variable_get(ivar)
|
119
|
+
headers.same_headers?(other.instance_variable_get(ivar))
|
120
|
+
when *REQUEST_IVARS
|
121
|
+
true
|
122
|
+
else
|
123
|
+
instance_variable_get(ivar) == other.instance_variable_get(ivar)
|
124
|
+
end
|
115
125
|
end
|
116
126
|
end
|
117
127
|
|
data/lib/httpx/parser/http1.rb
CHANGED
@@ -67,7 +67,8 @@ module HTTPX
|
|
67
67
|
@status_code = code.to_i
|
68
68
|
raise(Error, "wrong status code (#{@status_code})") unless (100..599).cover?(@status_code)
|
69
69
|
|
70
|
-
@buffer.slice!(0, idx + 1)
|
70
|
+
# @buffer.slice!(0, idx + 1)
|
71
|
+
@buffer = @buffer.byteslice((idx + 1)..-1)
|
71
72
|
nextstate(:headers)
|
72
73
|
end
|
73
74
|
|
@@ -116,7 +117,8 @@ module HTTPX
|
|
116
117
|
@observer.on_data(chunk)
|
117
118
|
end
|
118
119
|
elsif @content_length
|
119
|
-
data = @buffer.
|
120
|
+
data = @buffer.byteslice(0, @content_length)
|
121
|
+
@buffer = @buffer.byteslice(@content_length..-1) || "".b
|
120
122
|
@content_length -= data.bytesize
|
121
123
|
@observer.on_data(data)
|
122
124
|
data.clear
|
@@ -23,6 +23,14 @@ module HTTPX
|
|
23
23
|
options.merge(headers: { "accept-encoding" => Compression.registry.keys })
|
24
24
|
end
|
25
25
|
|
26
|
+
module RequestMethods
|
27
|
+
def initialize(*)
|
28
|
+
super
|
29
|
+
# forego compression in the Range cases
|
30
|
+
@headers.delete("accept-encoding") if @headers.key?("range")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
26
34
|
module RequestBodyMethods
|
27
35
|
def initialize(*)
|
28
36
|
super
|
@@ -36,14 +44,28 @@ module HTTPX
|
|
36
44
|
end
|
37
45
|
|
38
46
|
module ResponseBodyMethods
|
47
|
+
attr_reader :encodings
|
48
|
+
|
39
49
|
def initialize(*)
|
50
|
+
@encodings = []
|
51
|
+
|
40
52
|
super
|
41
53
|
|
42
54
|
return unless @headers.key?("content-encoding")
|
43
55
|
|
44
56
|
@_decoders = @headers.get("content-encoding").map do |encoding|
|
45
|
-
Compression.registry(encoding).decoder
|
57
|
+
decoder = Compression.registry(encoding).decoder
|
58
|
+
# do not uncompress if there is no decoder available. In fact, we can't reliably
|
59
|
+
# continue decompressing beyond that, so ignore.
|
60
|
+
break unless decoder
|
61
|
+
|
62
|
+
@encodings << encoding
|
63
|
+
decoder
|
46
64
|
end
|
65
|
+
|
66
|
+
# remove encodings that we are able to decode
|
67
|
+
@headers["content-encoding"] = @headers.get("content-encoding") - @encodings
|
68
|
+
|
47
69
|
@_compressed_length = if @headers.key?("content-length")
|
48
70
|
@headers["content-length"].to_i
|
49
71
|
else
|
@@ -60,7 +60,8 @@ module HTTPX::Transcoder
|
|
60
60
|
return unless index && index.positive?
|
61
61
|
|
62
62
|
# Read hex-length
|
63
|
-
hexlen = @buffer.
|
63
|
+
hexlen = @buffer.byteslice(0, index)
|
64
|
+
@buffer = @buffer.byteslice(index..-1) || "".b
|
64
65
|
hexlen[/\h/] || raise(Error, "wrong chunk size line: #{hexlen}")
|
65
66
|
@chunk_length = hexlen.hex
|
66
67
|
# check if is last chunk
|
@@ -72,7 +73,7 @@ module HTTPX::Transcoder
|
|
72
73
|
return if @buffer.bytesize < crlf_size
|
73
74
|
raise Error, "wrong chunked encoding format" unless @buffer.start_with?(CRLF * (crlf_size / 2))
|
74
75
|
|
75
|
-
@buffer.
|
76
|
+
@buffer = @buffer.byteslice(crlf_size..-1)
|
76
77
|
if @chunk_length.nil?
|
77
78
|
nextstate(:length)
|
78
79
|
else
|
@@ -81,8 +82,10 @@ module HTTPX::Transcoder
|
|
81
82
|
nextstate(:data)
|
82
83
|
end
|
83
84
|
when :data
|
84
|
-
|
85
|
-
@chunk_length
|
85
|
+
chunk = @buffer.byteslice(0, @chunk_length)
|
86
|
+
@buffer = @buffer.byteslice(@chunk_length..-1) || "".b
|
87
|
+
@chunk_buffer << chunk
|
88
|
+
@chunk_length -= chunk.bytesize
|
86
89
|
if @chunk_length.zero?
|
87
90
|
yield @chunk_buffer unless @chunk_buffer.empty?
|
88
91
|
@chunk_buffer.clear
|
data/lib/httpx/version.rb
CHANGED
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.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tiago Cardoso
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http-2
|