protocol-http1 0.19.1 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/protocol/http1/body/chunked.rb +2 -2
- data/lib/protocol/http1/body/fixed.rb +1 -3
- data/lib/protocol/http1/connection.rb +18 -2
- data/lib/protocol/http1/error.rb +9 -10
- data/lib/protocol/http1/version.rb +1 -1
- data/readme.md +3 -3
- data.tar.gz.sig +0 -0
- metadata +7 -5
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66ce05a20db2c35943a45feab35afe95bf530ce562030741984025defb1f0b40
|
4
|
+
data.tar.gz: e3066206a22ad274cc28ac13369d330cff0b5bee1641d79c113a3b13354f2f82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bfbfc8977ca31eb293ee61fa43cf042ecf10ee4342c7124880e2bda32b1d966fed74bf0ad02a083d8b3e52a0112482be04da3388e4b9424ec112ef8ddb4bee0
|
7
|
+
data.tar.gz: 204d66b3b7b57d3706248d05551cd29ccc50e824d34a4d0173cc90eb8266133abd5d6398cdc7811afb73d5605ca4b4a0107cbfb24679beff0e285616b9354307
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -45,7 +45,7 @@ module Protocol
|
|
45
45
|
length, _extensions = read_line.split(";", 2)
|
46
46
|
|
47
47
|
unless length =~ VALID_CHUNK_LENGTH
|
48
|
-
raise BadRequest, "Invalid chunk length: #{length.
|
48
|
+
raise BadRequest, "Invalid chunk length: #{length.inspect}"
|
49
49
|
end
|
50
50
|
|
51
51
|
# It is possible this line contains chunk extension, so we use `to_i` to only consider the initial integral part:
|
@@ -93,7 +93,7 @@ module Protocol
|
|
93
93
|
if match = line.match(HEADER)
|
94
94
|
@headers.add(match[1], match[2])
|
95
95
|
else
|
96
|
-
raise BadHeader, "Could not parse header: #{line.
|
96
|
+
raise BadHeader, "Could not parse header: #{line.inspect}"
|
97
97
|
end
|
98
98
|
end
|
99
99
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2019-
|
4
|
+
# Copyright, 2019-2024, by Samuel Williams.
|
5
5
|
|
6
6
|
require 'protocol/http/body/readable'
|
7
7
|
|
@@ -39,8 +39,6 @@ module Protocol
|
|
39
39
|
@remaining -= chunk.bytesize
|
40
40
|
|
41
41
|
return chunk
|
42
|
-
# else
|
43
|
-
# raise EOFError, "Stream closed with #{@remaining} bytes remaining!"
|
44
42
|
end
|
45
43
|
end
|
46
44
|
end
|
@@ -240,7 +240,7 @@ module Protocol
|
|
240
240
|
if match = line.match(HEADER)
|
241
241
|
fields << [match[1], match[2]]
|
242
242
|
else
|
243
|
-
raise BadHeader, "Could not parse header: #{line.
|
243
|
+
raise BadHeader, "Could not parse header: #{line.inspect}"
|
244
244
|
end
|
245
245
|
end
|
246
246
|
|
@@ -423,6 +423,7 @@ module Protocol
|
|
423
423
|
end
|
424
424
|
|
425
425
|
def read_remainder_body
|
426
|
+
@persistent = false
|
426
427
|
Body::Remainder.new(@stream)
|
427
428
|
end
|
428
429
|
|
@@ -434,6 +435,12 @@ module Protocol
|
|
434
435
|
read_remainder_body
|
435
436
|
end
|
436
437
|
|
438
|
+
def read_upgrade_body
|
439
|
+
# When you have an incoming upgrade request body, we must be extremely careful not to start reading it until the upgrade has been confirmed, otherwise if the upgrade was rejected and we started forwarding the incoming request body, it would desynchronize the connection (potential security issue).
|
440
|
+
# We mitigate this issue by setting @persistent to false, which will prevent the connection from being reused, even if the upgrade fails (potential performance issue).
|
441
|
+
read_remainder_body
|
442
|
+
end
|
443
|
+
|
437
444
|
HEAD = "HEAD"
|
438
445
|
CONNECT = "CONNECT"
|
439
446
|
|
@@ -444,7 +451,7 @@ module Protocol
|
|
444
451
|
if content_length =~ VALID_CONTENT_LENGTH
|
445
452
|
yield Integer(content_length, 10)
|
446
453
|
else
|
447
|
-
raise BadRequest, "Invalid content length: #{content_length.
|
454
|
+
raise BadRequest, "Invalid content length: #{content_length.inspect}"
|
448
455
|
end
|
449
456
|
end
|
450
457
|
end
|
@@ -469,6 +476,10 @@ module Protocol
|
|
469
476
|
return nil
|
470
477
|
end
|
471
478
|
|
479
|
+
if status == 101
|
480
|
+
return read_upgrade_body
|
481
|
+
end
|
482
|
+
|
472
483
|
if (status >= 100 and status < 200) or status == 204 or status == 304
|
473
484
|
return nil
|
474
485
|
end
|
@@ -495,6 +506,11 @@ module Protocol
|
|
495
506
|
return read_tunnel_body
|
496
507
|
end
|
497
508
|
|
509
|
+
# A successful upgrade response implies that the connection will become a tunnel immediately after the empty line that concludes the header fields.
|
510
|
+
if headers[UPGRADE]
|
511
|
+
return read_upgrade_body
|
512
|
+
end
|
513
|
+
|
498
514
|
# 6. If this is a request message and none of the above are true, then
|
499
515
|
# the message body length is zero (no message body is present).
|
500
516
|
return read_body(headers)
|
data/lib/protocol/http1/error.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2019-
|
4
|
+
# Copyright, 2019-2024, by Samuel Williams.
|
5
5
|
|
6
6
|
require 'protocol/http/error'
|
7
7
|
|
@@ -10,21 +10,20 @@ module Protocol
|
|
10
10
|
class Error < HTTP::Error
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# The specified content length and the given content's length do not match.
|
17
|
-
class ContentLengthError < Error
|
13
|
+
# The request was not able to be parsed correctly, or failed some kind of validation.
|
14
|
+
class BadRequest < Error
|
18
15
|
end
|
19
16
|
|
20
|
-
#
|
21
|
-
class
|
17
|
+
# A header name or value was invalid, e.g. contains invalid characters.
|
18
|
+
class BadHeader < BadRequest
|
22
19
|
end
|
23
20
|
|
24
|
-
|
21
|
+
# Indicates that the request is invalid for some reason, e.g. syntax error, invalid headers, etc.
|
22
|
+
class InvalidRequest < BadRequest
|
25
23
|
end
|
26
24
|
|
27
|
-
|
25
|
+
# The specified content length and the given content's length do not match.
|
26
|
+
class ContentLengthError < Error
|
28
27
|
end
|
29
28
|
end
|
30
29
|
end
|
data/readme.md
CHANGED
@@ -71,8 +71,8 @@ We welcome contributions to this project.
|
|
71
71
|
|
72
72
|
### Developer Certificate of Origin
|
73
73
|
|
74
|
-
|
74
|
+
In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
|
75
75
|
|
76
|
-
###
|
76
|
+
### Community Guidelines
|
77
77
|
|
78
|
-
This project is
|
78
|
+
This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
|
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.
|
4
|
+
version: 0.21.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-
|
45
|
+
date: 2024-09-02 00:00:00.000000000 Z
|
46
46
|
dependencies:
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: protocol-http
|
@@ -77,7 +77,9 @@ files:
|
|
77
77
|
homepage: https://github.com/socketry/protocol-http1
|
78
78
|
licenses:
|
79
79
|
- MIT
|
80
|
-
metadata:
|
80
|
+
metadata:
|
81
|
+
documentation_uri: https://socketry.github.io/protocol-http1/
|
82
|
+
source_code_uri: https://github.com/socketry/protocol-http1.git
|
81
83
|
post_install_message:
|
82
84
|
rdoc_options: []
|
83
85
|
require_paths:
|
@@ -86,14 +88,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
88
|
requirements:
|
87
89
|
- - ">="
|
88
90
|
- !ruby/object:Gem::Version
|
89
|
-
version: '3.
|
91
|
+
version: '3.1'
|
90
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
93
|
requirements:
|
92
94
|
- - ">="
|
93
95
|
- !ruby/object:Gem::Version
|
94
96
|
version: '0'
|
95
97
|
requirements: []
|
96
|
-
rubygems_version: 3.5.
|
98
|
+
rubygems_version: 3.5.11
|
97
99
|
signing_key:
|
98
100
|
specification_version: 4
|
99
101
|
summary: A low level implementation of the HTTP/1 protocol.
|
metadata.gz.sig
CHANGED
Binary file
|