http 4.0.4 → 4.0.5

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: 3c750c774b9ba9cef7d527d45863f20afe38fb2dada51404f555b3465c9d2ba5
4
- data.tar.gz: c0421af748f924466afe818a52dc7a02598010446aa1c91e40ac02ca82278b43
3
+ metadata.gz: 94fd7f54004fd45a400c1e9befb46ea80d4bcdebae70929330355a5ea9056cf2
4
+ data.tar.gz: 3bbd9c1f0a29267bff2b6682ddaeaa53832eb896ec471d6ab3db62d5cbd08be2
5
5
  SHA512:
6
- metadata.gz: 6a7e7d036484d7145f5cc8a5c077dbed71783125ebeedeb5965c0648a01d0dc596baed4b209a150a1e0848d3002eb285f16fe804c74ecca90a97d3a4f1871d5a
7
- data.tar.gz: fb1c8d8c5ca3c4b8aa5f863d789e47516c8e19dc2ad4f132b8be8509b766fc0e3a8d3ddddc1233db8fc816dc6bc6f0acff80ead1fb5515e1d48cb10b4fd031f9
6
+ metadata.gz: 5863fb462013166b6f76ff40929768f5a87ca86c02bd23c882bf5db1aefa6bed5be2a21785a45edecf66f6a6ac3418d86042b5c24f998e1f01489a661a1d9cae
7
+ data.tar.gz: 04726c6858928f553380fbb221cc1164cc51917ae2122cd9b7424ef3f1ff072c7b32ae2231cb32569a4411487f6c805acee54ec09e309e6eba4675a783df8306
data/CHANGES.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 4.0.5 (2019-02-15)
2
+
3
+ * Backport [#532](https://github.com/httprb/http/pull/532) from master.
4
+ Fix pipes support in request bodies.
5
+ ([@ixti])
6
+
7
+
1
8
  ## 4.0.4 (2019-02-12)
2
9
 
3
10
  * Backport [#506](https://github.com/httprb/http/pull/506) from master.
@@ -35,10 +35,12 @@ module HTTP
35
35
  yield @source
36
36
  elsif @source.respond_to?(:read)
37
37
  IO.copy_stream(@source, ProcIO.new(block))
38
- @source.rewind if @source.respond_to?(:rewind)
38
+ rewind(@source)
39
39
  elsif @source.is_a?(Enumerable)
40
40
  @source.each(&block)
41
41
  end
42
+
43
+ self
42
44
  end
43
45
 
44
46
  # Request bodies are equivalent when they have the same source.
@@ -48,6 +50,28 @@ module HTTP
48
50
 
49
51
  private
50
52
 
53
+ def rewind(io)
54
+ io.rewind if io.respond_to? :rewind
55
+ rescue Errno::ESPIPE, Errno::EPIPE
56
+ # Pipe IOs respond to `:rewind` but fail when you call it.
57
+ #
58
+ # Calling `IO#rewind` on a pipe, fails with *ESPIPE* on MRI,
59
+ # but *EPIPE* on jRuby.
60
+ #
61
+ # - **ESPIPE** -- "Illegal seek."
62
+ # Invalid seek operation (such as on a pipe).
63
+ #
64
+ # - **EPIPE** -- "Broken pipe."
65
+ # There is no process reading from the other end of a pipe. Every
66
+ # library function that returns this error code also generates
67
+ # a SIGPIPE signal; this signal terminates the program if not handled
68
+ # or blocked. Thus, your program will never actually see EPIPE unless
69
+ # it has handled or blocked SIGPIPE.
70
+ #
71
+ # See: https://www.gnu.org/software/libc/manual/html_node/Error-Codes.html
72
+ nil
73
+ end
74
+
51
75
  def validate_source_type!
52
76
  return if @source.is_a?(String)
53
77
  return if @source.respond_to?(:read)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTP
4
- VERSION = "4.0.4"
4
+ VERSION = "4.0.5"
5
5
  end
@@ -125,6 +125,28 @@ RSpec.describe HTTP::Request::Body do
125
125
  end
126
126
  end
127
127
 
128
+ context "when body is a pipe" do
129
+ let(:ios) { IO.pipe }
130
+ let(:body) { ios[0] }
131
+
132
+ around do |example|
133
+ writer = Thread.new(ios[1]) do |io|
134
+ io << "abcdef"
135
+ io.close
136
+ end
137
+
138
+ begin
139
+ example.run
140
+ ensure
141
+ writer.join
142
+ end
143
+ end
144
+
145
+ it "yields chunks of content" do
146
+ expect(chunks.inject("", :+)).to eq("abcdef")
147
+ end
148
+ end
149
+
128
150
  context "when body is an Enumerable IO" do
129
151
  let(:data) { "a" * 16 * 1024 + "b" * 10 * 1024 }
130
152
  let(:body) { StringIO.new data }
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: 4.0.4
4
+ version: 4.0.5
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: 2019-02-12 00:00:00.000000000 Z
14
+ date: 2019-02-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: http_parser.rb