protocol-http1 0.15.0 → 0.16.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: c1c040780ba6a7bae3e921d5a7ff40ba5e656ce66d8a138d2c5382ce42efc317
4
- data.tar.gz: 551dbe0ecbc187b7b3c0c86507d737eace6b41c4f3b62f0d8a7c6f6d8b0bd0a2
3
+ metadata.gz: bd649e1cfc933db22108e92849ddbe40f516b5f37c5c9b01db704764c445554c
4
+ data.tar.gz: 3c38f467000c80e62831ca4d4ecf19e787ea7176871461d228e6d7817198580a
5
5
  SHA512:
6
- metadata.gz: a57fcfd40cf929f6e6a096d07513378b6631d5dbdab25431c9c8763fea9e4a1967e77adc8bddc55a2ca8eb5b3232088bbaf9d0af1fed8dad05af20e3702e4ef2
7
- data.tar.gz: f736986596addfec4908e05d9bf632f79f906cf1508076ec7e5dd5de1e08efee33c9c1edd512aef50c4f483db92b92481ba68929edbefe454db57b445b969f8c
6
+ metadata.gz: 2db727958d638bb129d1062fa22ca1149994c41c5a3b23ca2b50409e0d761e2494f959aa21d407bd2cf9019754707d13a46a7e4c33a2001fac1dcee8f65cd211
7
+ data.tar.gz: e4c2a03cf2c9d2e021a81c5e63a9366875e521d8c6847e101fc64d9955f5fe84da79e05aaa54e6c1aa388c46edb791367573240e50743d5a0e54565028c8e3c0
checksums.yaml.gz.sig CHANGED
Binary file
@@ -35,12 +35,20 @@ module Protocol
35
35
  super
36
36
  end
37
37
 
38
+ VALID_CHUNK_LENGTH = /\A[0-9a-fA-F]+\z/
39
+
38
40
  # Follows the procedure outlined in https://tools.ietf.org/html/rfc7230#section-4.1.3
39
41
  def read
40
42
  return nil if @finished
41
43
 
44
+ length, _extensions = read_line.split(";", 2)
45
+
46
+ unless length =~ VALID_CHUNK_LENGTH
47
+ raise BadRequest, "Invalid chunk length: #{length.dump}"
48
+ end
49
+
42
50
  # It is possible this line contains chunk extension, so we use `to_i` to only consider the initial integral part:
43
- length = read_line.to_i(16)
51
+ length = Integer(length, 16)
44
52
 
45
53
  if length == 0
46
54
  @finished = true
@@ -128,6 +128,15 @@ module Protocol
128
128
  write_headers(headers)
129
129
  end
130
130
 
131
+ def write_interim_response(version, status, headers, reason = Reason::DESCRIPTIONS[status])
132
+ @stream.write("#{version} #{status} #{reason}\r\n")
133
+
134
+ write_headers(headers)
135
+
136
+ @stream.write("\r\n")
137
+ @stream.flush
138
+ end
139
+
131
140
  def write_headers(headers)
132
141
  headers.each do |name, value|
133
142
  # Convert it to a string:
@@ -398,12 +407,14 @@ module Protocol
398
407
  HEAD = "HEAD"
399
408
  CONNECT = "CONNECT"
400
409
 
410
+ VALID_CONTENT_LENGTH = /\A\d+\z/
411
+
401
412
  def extract_content_length(headers)
402
413
  if content_length = headers.delete(CONTENT_LENGTH)
403
- if length = Integer(content_length, exception: false) and length >= 0
404
- yield length
414
+ if content_length =~ VALID_CONTENT_LENGTH
415
+ yield Integer(content_length, 10)
405
416
  else
406
- raise BadRequest, "Invalid content length: #{content_length}"
417
+ raise BadRequest, "Invalid content length: #{content_length.dump}"
407
418
  end
408
419
  end
409
420
  end
@@ -1,10 +1,10 @@
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-2023, by Samuel Williams.
5
5
 
6
6
  module Protocol
7
7
  module HTTP1
8
- VERSION = "0.15.0"
8
+ VERSION = "0.16.0"
9
9
  end
10
10
  end
data/readme.md CHANGED
@@ -61,32 +61,18 @@ end
61
61
 
62
62
  ## Contributing
63
63
 
64
- 1. Fork it
65
- 2. Create your feature branch (`git checkout -b my-new-feature`)
66
- 3. Commit your changes (`git commit -am 'Add some feature'`)
67
- 4. Push to the branch (`git push origin my-new-feature`)
68
- 5. Create new Pull Request
69
-
70
- ## License
71
-
72
- Released under the MIT license.
73
-
74
- Copyright, 2019, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
75
-
76
- Permission is hereby granted, free of charge, to any person obtaining a copy
77
- of this software and associated documentation files (the "Software"), to deal
78
- in the Software without restriction, including without limitation the rights
79
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
80
- copies of the Software, and to permit persons to whom the Software is
81
- furnished to do so, subject to the following conditions:
82
-
83
- The above copyright notice and this permission notice shall be included in
84
- all copies or substantial portions of the Software.
85
-
86
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
87
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
88
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
89
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
90
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
91
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
92
- THE SOFTWARE.
64
+ We welcome contributions to this project.
65
+
66
+ 1. Fork it.
67
+ 2. Create your feature branch (`git checkout -b my-new-feature`).
68
+ 3. Commit your changes (`git commit -am 'Add some feature'`).
69
+ 4. Push to the branch (`git push origin my-new-feature`).
70
+ 5. Create new Pull Request.
71
+
72
+ ### Developer Certificate of Origin
73
+
74
+ This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.
75
+
76
+ ### Contributor Covenant
77
+
78
+ This project is governed by [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
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.15.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -40,7 +40,7 @@ cert_chain:
40
40
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
41
41
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
42
42
  -----END CERTIFICATE-----
43
- date: 2023-01-30 00:00:00.000000000 Z
43
+ date: 2023-10-24 00:00:00.000000000 Z
44
44
  dependencies:
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: protocol-http
@@ -56,48 +56,6 @@ dependencies:
56
56
  - - "~>"
57
57
  - !ruby/object:Gem::Version
58
58
  version: '0.22'
59
- - !ruby/object:Gem::Dependency
60
- name: bundler
61
- requirement: !ruby/object:Gem::Requirement
62
- requirements:
63
- - - ">="
64
- - !ruby/object:Gem::Version
65
- version: '0'
66
- type: :development
67
- prerelease: false
68
- version_requirements: !ruby/object:Gem::Requirement
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: '0'
73
- - !ruby/object:Gem::Dependency
74
- name: covered
75
- requirement: !ruby/object:Gem::Requirement
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- version: '0'
80
- type: :development
81
- prerelease: false
82
- version_requirements: !ruby/object:Gem::Requirement
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- version: '0'
87
- - !ruby/object:Gem::Dependency
88
- name: sus
89
- requirement: !ruby/object:Gem::Requirement
90
- requirements:
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- version: '0'
94
- type: :development
95
- prerelease: false
96
- version_requirements: !ruby/object:Gem::Requirement
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- version: '0'
101
59
  description:
102
60
  email:
103
61
  executables: []
@@ -126,14 +84,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
84
  requirements:
127
85
  - - ">="
128
86
  - !ruby/object:Gem::Version
129
- version: '2.4'
87
+ version: 2.7.6b
130
88
  required_rubygems_version: !ruby/object:Gem::Requirement
131
89
  requirements:
132
90
  - - ">="
133
91
  - !ruby/object:Gem::Version
134
92
  version: '0'
135
93
  requirements: []
136
- rubygems_version: 3.4.1
94
+ rubygems_version: 3.4.10
137
95
  signing_key:
138
96
  specification_version: 4
139
97
  summary: A low level implementation of the HTTP/1 protocol.
metadata.gz.sig CHANGED
Binary file