protocol-http1 0.22.0 → 0.23.0

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: 550b6e9b8f04f40fbba30a9260ead61bc1921130b069f8d4f6d7005077da0e61
4
- data.tar.gz: 54a8009f974a0292b1500c21f7e8047d5af4d815e7b844fa46ec0d6f6d356fee
3
+ metadata.gz: 5883f7878058a83c35d40fe91ea7e673a6abc1895d47e91dfefd57e1849861d5
4
+ data.tar.gz: f01fbad8aa91e32dddd541fa6a3ab184d8204a5761b6a0b2d5bd7eafd5aab717
5
5
  SHA512:
6
- metadata.gz: e44973d7e04933d1e6d3e8d50c98dcc57603fc4cd7491a1ab9ed490ef659551bbf1e0eb425222cc2e61f38b9fc5af864198970505a42750dad8c97bdb68331e7
7
- data.tar.gz: 6fba9bb8ac29bc13966bbebed00ca72b60d9214ba1943185e44760abb72ad5b1fa8254f4222951e5bf983263fef015a78ecdca6e6c8396c3c0e9548bade51576
6
+ metadata.gz: de91d508479206879dfded7ef4aca6ec5b211372ae8aa9d938afb97c4cb5d1804e9aefbea42d021979ce3c67ad6cf96c28f661be62e6c191219204f9ba96267e
7
+ data.tar.gz: 3c556ecfd10f3b20424629898b4684e6f8d56ad7415c94e3fedcac7485d5fb389141fd2fb9a9bbadd67a20d05a51286e338fc656febe145551b491781c052776
checksums.yaml.gz.sig CHANGED
Binary file
@@ -4,7 +4,7 @@
4
4
  # Copyright, 2019-2024, by Samuel Williams.
5
5
  # Copyright, 2023, by Thomas Morgan.
6
6
 
7
- require 'protocol/http/body/readable'
7
+ require "protocol/http/body/readable"
8
8
 
9
9
  module Protocol
10
10
  module HTTP1
@@ -26,15 +26,19 @@ module Protocol
26
26
  @stream.nil?
27
27
  end
28
28
 
29
- def close(error = nil)
30
- if @stream
29
+ def discard
30
+ if stream = @stream
31
+ @stream = nil
32
+
31
33
  # We only close the connection if we haven't completed reading the entire body:
32
34
  unless @finished
33
- @stream.close_read
35
+ stream.close_read
34
36
  end
35
-
36
- @stream = nil
37
37
  end
38
+ end
39
+
40
+ def close(error = nil)
41
+ self.discard
38
42
 
39
43
  super
40
44
  end
@@ -67,13 +71,18 @@ module Protocol
67
71
  # Read trailing CRLF:
68
72
  chunk = @stream.read(length + 2)
69
73
 
70
- # ...and chomp it off:
71
- chunk.chomp!(CRLF)
72
-
73
- @length += length
74
- @count += 1
75
-
76
- return chunk
74
+ if chunk.bytesize == length + 2
75
+ # ...and chomp it off:
76
+ chunk.chomp!(CRLF)
77
+
78
+ @length += length
79
+ @count += 1
80
+
81
+ return chunk
82
+ else
83
+ # The stream has been closed before we have read the requested length:
84
+ self.discard
85
+ end
77
86
  end
78
87
 
79
88
  # If the stream has been closed before we have read the final chunk, raise an error:
@@ -3,7 +3,7 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
- require 'protocol/http/body/readable'
6
+ require "protocol/http/body/readable"
7
7
 
8
8
  module Protocol
9
9
  module HTTP1
@@ -23,15 +23,18 @@ module Protocol
23
23
  @stream.nil? or @remaining == 0
24
24
  end
25
25
 
26
- def close(error = nil)
27
- if @stream
28
- # If we are closing the body without fully reading it, the underlying connection is now in an undefined state.
26
+ def discard
27
+ if stream = @stream
28
+ @stream = nil
29
+
29
30
  if @remaining != 0
30
- @stream.close_read
31
+ stream.close_read
31
32
  end
32
-
33
- @stream = nil
34
33
  end
34
+ end
35
+
36
+ def close(error = nil)
37
+ self.discard
35
38
 
36
39
  super
37
40
  end
@@ -41,11 +44,11 @@ module Protocol
41
44
  if @remaining > 0
42
45
  if @stream
43
46
  # `readpartial` will raise `EOFError` if the stream is finished, or `IOError` if the stream is closed.
44
- if chunk = @stream.readpartial(@remaining)
45
- @remaining -= chunk.bytesize
46
-
47
- return chunk
48
- end
47
+ chunk = @stream.readpartial(@remaining)
48
+
49
+ @remaining -= chunk.bytesize
50
+
51
+ return chunk
49
52
  end
50
53
 
51
54
  # If the stream has been closed before we have read the expected length, raise an error:
@@ -3,7 +3,7 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
- require 'protocol/http/body/readable'
6
+ require "protocol/http/body/readable"
7
7
 
8
8
  module Protocol
9
9
  module HTTP1
@@ -21,12 +21,15 @@ module Protocol
21
21
  @stream.nil?
22
22
  end
23
23
 
24
- def close(error = nil)
25
- if @stream
26
- # We can't really do anything in this case except close the connection.
27
- @stream.close_read
24
+ def discard
25
+ if stream = @stream
28
26
  @stream = nil
27
+ stream.close_read
29
28
  end
29
+ end
30
+
31
+ def close(error = nil)
32
+ self.discard
30
33
 
31
34
  super
32
35
  end
@@ -7,31 +7,31 @@
7
7
  # Copyright, 2023-2024, by Thomas Morgan.
8
8
  # Copyright, 2024, by Anton Zhuravsky.
9
9
 
10
- require 'protocol/http/headers'
10
+ require "protocol/http/headers"
11
11
 
12
- require_relative 'reason'
13
- require_relative 'error'
12
+ require_relative "reason"
13
+ require_relative "error"
14
14
 
15
- require_relative 'body/chunked'
16
- require_relative 'body/fixed'
17
- require_relative 'body/remainder'
18
- require 'protocol/http/body/head'
15
+ require_relative "body/chunked"
16
+ require_relative "body/fixed"
17
+ require_relative "body/remainder"
18
+ require "protocol/http/body/head"
19
19
 
20
- require 'protocol/http/methods'
20
+ require "protocol/http/methods"
21
21
 
22
22
  module Protocol
23
23
  module HTTP1
24
- CONTENT_LENGTH = 'content-length'
24
+ CONTENT_LENGTH = "content-length"
25
25
 
26
- TRANSFER_ENCODING = 'transfer-encoding'
27
- CHUNKED = 'chunked'
26
+ TRANSFER_ENCODING = "transfer-encoding"
27
+ CHUNKED = "chunked"
28
28
 
29
- CONNECTION = 'connection'
30
- CLOSE = 'close'
31
- KEEP_ALIVE = 'keep-alive'
29
+ CONNECTION = "connection"
30
+ CLOSE = "close"
31
+ KEEP_ALIVE = "keep-alive"
32
32
 
33
- HOST = 'host'
34
- UPGRADE = 'upgrade'
33
+ HOST = "host"
34
+ UPGRADE = "upgrade"
35
35
 
36
36
  # HTTP/1.x request line parser:
37
37
  TOKEN = /[!#$%&'*+\-\.\^_`|~0-9a-zA-Z]+/.freeze
@@ -3,7 +3,7 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
- require 'protocol/http/error'
6
+ require "protocol/http/error"
7
7
 
8
8
  module Protocol
9
9
  module HTTP1
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2022, by Samuel Williams.
4
+ # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
- require 'protocol/http/error'
6
+ require "protocol/http/error"
7
7
 
8
8
  module Protocol
9
9
  module HTTP1
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module HTTP1
8
- VERSION = "0.22.0"
8
+ VERSION = "0.23.0"
9
9
  end
10
10
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2022, by Samuel Williams.
4
+ # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
- require_relative 'http1/version'
7
- require_relative 'http1/connection'
6
+ require_relative "http1/version"
7
+ require_relative "http1/connection"
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-http1
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -42,7 +42,7 @@ cert_chain:
42
42
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
43
43
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
44
44
  -----END CERTIFICATE-----
45
- date: 2024-09-05 00:00:00.000000000 Z
45
+ date: 2024-09-17 00:00:00.000000000 Z
46
46
  dependencies:
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: protocol-http
metadata.gz.sig CHANGED
Binary file