protocol-http1 0.15.1 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 628996f62e649fce9998463a3147bba9690074ccd422d8973b56840f169ddbef
4
- data.tar.gz: 368fd3265a87abe2f0300741f568194d5f479121fd49ccf51e0fdce6725dd080
3
+ metadata.gz: f969e504112849ed6eccb047bd8e240fc79dc92efd2835f8676469064fe2656c
4
+ data.tar.gz: 25ffd9feeede23158051a130c5047f80a1f6f72b5c438e9adbc7fc1296add536
5
5
  SHA512:
6
- metadata.gz: c3b589a20fb9395b6245ace8b113b7c57f541e9077562cece7673e8ba3577c0825bc71ed229902447e7abc735e126e6d2cd7a2b4a5b9385e24b5e5fb7c3596da
7
- data.tar.gz: 15ff254cb06790546e76b00de892c10e712eb42ca30629b9c527d90034c252993c9de71be6d6b9f3f0cb26745ab554cf71e75e63e18a8b847c510d2bad16d45c
6
+ metadata.gz: 0b40ee03ea89a7daf74e3e93a441b2ff2f1933657bb95440682d9eacf85487523a38a7fe1ef5aed251a2d784f0fd8b5cb87d674561a579b1f928ef104b7ef5d7
7
+ data.tar.gz: 7063c346d1de2461b0ad5ee40aaa9b3992f0eb37f5930ba62869bc1b01df0d3c91b268e65a757bb98026b740036796a3e42a85add7bd7421a2e098bdd79a4fd0
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,7 +1,8 @@
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
+ # Copyright, 2023, by Thomas Morgan.
5
6
 
6
7
  require 'protocol/http/body/readable'
7
8
 
@@ -41,7 +42,7 @@ module Protocol
41
42
  def read
42
43
  return nil if @finished
43
44
 
44
- length, extensions = read_line.split(";", 2)
45
+ length, _extensions = read_line.split(";", 2)
45
46
 
46
47
  unless length =~ VALID_CHUNK_LENGTH
47
48
  raise BadRequest, "Invalid chunk length: #{length.dump}"
@@ -4,6 +4,7 @@
4
4
  # Copyright, 2019-2023, by Samuel Williams.
5
5
  # Copyright, 2019, by Brian Morearty.
6
6
  # Copyright, 2020, by Bruno Sutic.
7
+ # Copyright, 2023, by Thomas Morgan.
7
8
 
8
9
  require 'protocol/http/headers'
9
10
 
@@ -59,7 +60,14 @@ module Protocol
59
60
  attr :stream
60
61
 
61
62
  # Whether the connection is persistent.
62
- attr :persistent
63
+ # This determines what connection headers are sent in the response and whether
64
+ # the connection can be reused after the response is sent.
65
+ # This setting is automatically managed according to the nature of the request
66
+ # and response.
67
+ # Changing to false is safe.
68
+ # Changing to true from outside this class should generally be avoided and,
69
+ # depending on the response semantics, may be reset to false anyway.
70
+ attr_accessor :persistent
63
71
 
64
72
  # The number of requests processed.
65
73
  attr :count
@@ -128,6 +136,15 @@ module Protocol
128
136
  write_headers(headers)
129
137
  end
130
138
 
139
+ def write_interim_response(version, status, headers, reason = Reason::DESCRIPTIONS[status])
140
+ @stream.write("#{version} #{status} #{reason}\r\n")
141
+
142
+ write_headers(headers)
143
+
144
+ @stream.write("\r\n")
145
+ @stream.flush
146
+ end
147
+
131
148
  def write_headers(headers)
132
149
  headers.each do |name, value|
133
150
  # Convert it to a string:
@@ -156,7 +173,7 @@ module Protocol
156
173
  read_line? or raise EOFError
157
174
  end
158
175
 
159
- def read_request
176
+ def read_request_line
160
177
  return unless line = read_line?
161
178
 
162
179
  if match = line.match(REQUEST_LINE)
@@ -165,6 +182,13 @@ module Protocol
165
182
  raise InvalidRequest, line.inspect
166
183
  end
167
184
 
185
+ return method, path, version
186
+ end
187
+
188
+ def read_request
189
+ method, path, version = read_request_line
190
+ return unless method
191
+
168
192
  headers = read_headers
169
193
 
170
194
  @persistent = persistent?(version, method, headers)
@@ -176,11 +200,17 @@ module Protocol
176
200
  return headers.delete(HOST), method, path, version, headers, body
177
201
  end
178
202
 
179
- def read_response(method)
203
+ def read_response_line
180
204
  version, status, reason = read_line.split(/\s+/, 3)
181
205
 
182
206
  status = Integer(status)
183
207
 
208
+ return version, status, reason
209
+ end
210
+
211
+ def read_response(method)
212
+ version, status, reason = read_response_line
213
+
184
214
  headers = read_headers
185
215
 
186
216
  @persistent = persistent?(version, method, headers)
@@ -405,7 +435,7 @@ module Protocol
405
435
  if content_length =~ VALID_CONTENT_LENGTH
406
436
  yield Integer(content_length, 10)
407
437
  else
408
- raise BadRequest, "Invalid content length: #{content_length}"
438
+ raise BadRequest, "Invalid content length: #{content_length.dump}"
409
439
  end
410
440
  end
411
441
  end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module HTTP1
8
- VERSION = "0.15.1"
8
+ VERSION = "0.16.1"
9
9
  end
10
10
  end
data/license.md CHANGED
@@ -4,6 +4,7 @@ Copyright, 2019-2023, by Samuel Williams.
4
4
  Copyright, 2019, by Brian Morearty.
5
5
  Copyright, 2020, by Olle Jonsson.
6
6
  Copyright, 2020, by Bruno Sutic.
7
+ Copyright, 2023, by Thomas Morgan.
7
8
 
8
9
  Permission is hereby granted, free of charge, to any person obtaining a copy
9
10
  of this software and associated documentation files (the "Software"), to deal
data/readme.md CHANGED
@@ -75,4 +75,4 @@ This project uses the [Developer Certificate of Origin](https://developercertifi
75
75
 
76
76
  ### Contributor Covenant
77
77
 
78
- This project is governed by [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
78
+ This project is governed by the [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,10 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-http1
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.1
4
+ version: 0.16.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
+ - Thomas Morgan
8
9
  - Brian Morearty
9
10
  - Bruno Sutic
10
11
  - Olle Jonsson
@@ -40,7 +41,7 @@ cert_chain:
40
41
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
41
42
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
42
43
  -----END CERTIFICATE-----
43
- date: 2023-07-30 00:00:00.000000000 Z
44
+ date: 2023-12-26 00:00:00.000000000 Z
44
45
  dependencies:
45
46
  - !ruby/object:Gem::Dependency
46
47
  name: protocol-http
@@ -84,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
85
  requirements:
85
86
  - - ">="
86
87
  - !ruby/object:Gem::Version
87
- version: 2.7.6b
88
+ version: '3.0'
88
89
  required_rubygems_version: !ruby/object:Gem::Requirement
89
90
  requirements:
90
91
  - - ">="
metadata.gz.sig CHANGED
Binary file