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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 788a7cdaae8c9fff36170e86592e43a06a793426dfb238a64178d278e5a9251e
4
- data.tar.gz: 82627e3f5a65fae019e34a44ac6fb13956d14bcc59e1d1210c18d669c235621d
3
+ metadata.gz: 66ce05a20db2c35943a45feab35afe95bf530ce562030741984025defb1f0b40
4
+ data.tar.gz: e3066206a22ad274cc28ac13369d330cff0b5bee1641d79c113a3b13354f2f82
5
5
  SHA512:
6
- metadata.gz: f3532ee1607c47d0967772b13a87facf7639218a075b859f6919eb669e2f52fda1aa8b1435bc708e6f45110401aa850759578cb14193156d00422d855b9a8547
7
- data.tar.gz: 3736f3807b61c4c6d2297931838aff49b9cd8f5263b10fa42ed512e812a2a141974c99af8593ae83dc49fcc580f21817397aee82ea20460563f6418c910fa9f4
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.dump}"
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.dump}"
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-2023, by Samuel Williams.
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.dump}"
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.dump}"
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)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2023, by Samuel Williams.
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
- class InvalidRequest < Error
14
- end
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
- # The request was parsed correctly, but was invalid for some other reason.
21
- class BadRequest < Error
17
+ # A header name or value was invalid, e.g. contains invalid characters.
18
+ class BadHeader < BadRequest
22
19
  end
23
20
 
24
- class BadHeader < Error
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
- class BadResponse < Error
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
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module HTTP1
8
- VERSION = "0.19.1"
8
+ VERSION = "0.21.0"
9
9
  end
10
10
  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
- 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.
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
- ### Contributor Covenant
76
+ ### Community Guidelines
77
77
 
78
- This project is governed by the [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
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.19.1
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-04-20 00:00:00.000000000 Z
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.0'
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.3
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