protocol-http 0.67.0 → 0.69.0

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: d934169186f9f7d3d55577ad02463aca42c88ba3e00b3273e3b6727f8c1b0e06
4
- data.tar.gz: b8a13b51e95c6cda67717ad822cdc4b46828feefe6802374de6446c6d1a34f9d
3
+ metadata.gz: e15c95aaaa592e283652205e025ad4473e3f082865506604799bb8eaadf06368
4
+ data.tar.gz: 10b0bf633c92acbec2fb96a70e5693060cab025e2df7ea45aaad410ba9c7afad
5
5
  SHA512:
6
- metadata.gz: d3bc1abcbef44eef390a2de0d4b17d8ebbec0a20180022f43d7e9aaeff0cf153027fec6d7e6b7968fd546dd9b8a321139f8966008acc2f7502f751af34bc5f1a
7
- data.tar.gz: 733a70b325bcb1db25f9d21b2fd93be191d9cedf1a521bb386f88e028b47411c692a51f38d25f5381f840a143a9296e1e7a04d444bbf3089296b1e7bd02f9e41
6
+ metadata.gz: 99165410a3df8b9efef707e17e1ea31befa3510a65c111a77d17270ffb9167f15d36d6bc64512ee2d7aea2ff3cf5087379e7826ce54595087f89d227eb42f9b6
7
+ data.tar.gz: 297e0e29550b333cfa5f35005263e9762ff8afc64c6ca9e1f76ca1fcfb0c0b9ea3a7364f81f8349aced4b9aa018d7892b5362863896d0827f0d4daec9fd0c648
checksums.yaml.gz.sig CHANGED
Binary file
@@ -4,6 +4,8 @@
4
4
  # Copyright, 2019-2024, by Samuel Williams.
5
5
  # Copyright, 2023, by Bruno Sutic.
6
6
 
7
+ require_relative "stream"
8
+
7
9
  module Protocol
8
10
  module HTTP
9
11
  module Body
@@ -186,6 +188,12 @@ module Protocol
186
188
  def to_json(...)
187
189
  as_json.to_json(...)
188
190
  end
191
+
192
+ # Return an IO-compatible stream for reading this body.
193
+ # @returns [Stream] The IO-compatible stream adapter.
194
+ def to_io
195
+ return Stream.new(self)
196
+ end
189
197
  end
190
198
  end
191
199
  end
@@ -5,8 +5,6 @@
5
5
  # Copyright, 2023, by Genki Takiuchi.
6
6
  # Copyright, 2025, by William T. Nelson.
7
7
 
8
- require_relative "buffered"
9
-
10
8
  module Protocol
11
9
  module HTTP
12
10
  module Body
@@ -17,13 +15,15 @@ module Protocol
17
15
 
18
16
  # Initialize the stream with the given input and output.
19
17
  #
20
- # @parameter input [Readable] The input stream.
21
- # @parameter output [Writable] The output stream.
22
- def initialize(input = nil, output = Buffered.new)
18
+ # @parameter input [Readable | Nil] The input stream.
19
+ # @parameter output [Writable | Nil] The output stream.
20
+ def initialize(input = nil, output = nil)
23
21
  @input = input
24
22
  @output = output
25
23
 
26
- raise ArgumentError, "Non-writable output!" unless output.respond_to?(:write)
24
+ if @output
25
+ raise ArgumentError, "Non-writable output!" unless output.respond_to?(:write)
26
+ end
27
27
 
28
28
  # Will hold remaining data in `#read`.
29
29
  @buffer = nil
@@ -32,10 +32,10 @@ module Protocol
32
32
  @closed_read = false
33
33
  end
34
34
 
35
- # @attribute [Readable] The input stream.
35
+ # @attribute [Readable | Nil] The input stream.
36
36
  attr :input
37
37
 
38
- # @attribute [Writable] The output stream.
38
+ # @attribute [Writable | Nil] The output stream.
39
39
  attr :output
40
40
 
41
41
  # This provides a read-only interface for data, which is surprisingly tricky to implement correctly.
@@ -409,7 +409,11 @@ module Protocol
409
409
 
410
410
  # @returns [Boolean] Whether there are any output chunks remaining.
411
411
  def empty?
412
- @output.empty?
412
+ if @output
413
+ return @output.empty?
414
+ else
415
+ return true
416
+ end
413
417
  end
414
418
 
415
419
  private
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2026, by Samuel Williams.
5
+
6
+ module Protocol
7
+ module HTTP
8
+ # HTTP status codes and their human-readable descriptions.
9
+ module Status
10
+ # Human-readable descriptions for registered and conventional HTTP status codes.
11
+ DESCRIPTIONS = {
12
+ 100 => "Continue",
13
+ 101 => "Switching Protocols",
14
+ 102 => "Processing",
15
+ 103 => "Early Hints",
16
+
17
+ 200 => "OK",
18
+ 201 => "Created",
19
+ 202 => "Accepted",
20
+ 203 => "Non-Authoritative Information",
21
+ 204 => "No Content",
22
+ 205 => "Reset Content",
23
+ 206 => "Partial Content",
24
+ 207 => "Multi-Status",
25
+ 208 => "Already Reported",
26
+ 226 => "IM Used",
27
+
28
+ 300 => "Multiple Choices",
29
+ 301 => "Moved Permanently",
30
+ 302 => "Found",
31
+ 303 => "See Other",
32
+ 304 => "Not Modified",
33
+ 305 => "Use Proxy",
34
+ 306 => "Switch Proxy",
35
+ 307 => "Temporary Redirect",
36
+ 308 => "Permanent Redirect",
37
+
38
+ 400 => "Bad Request",
39
+ 401 => "Unauthorized",
40
+ 402 => "Payment Required",
41
+ 403 => "Forbidden",
42
+ 404 => "Not Found",
43
+ 405 => "Method Not Allowed",
44
+ 406 => "Not Acceptable",
45
+ 407 => "Proxy Authentication Required",
46
+ 408 => "Request Timeout",
47
+ 409 => "Conflict",
48
+ 410 => "Gone",
49
+ 411 => "Length Required",
50
+ 412 => "Precondition Failed",
51
+ 413 => "Content Too Large",
52
+ 414 => "URI Too Long",
53
+ 415 => "Unsupported Media Type",
54
+ 416 => "Range Not Satisfiable",
55
+ 417 => "Expectation Failed",
56
+ 418 => "I'm a Teapot",
57
+ 421 => "Misdirected Request",
58
+ 422 => "Unprocessable Content",
59
+ 423 => "Locked",
60
+ 424 => "Failed Dependency",
61
+ 425 => "Too Early",
62
+ 426 => "Upgrade Required",
63
+ 428 => "Precondition Required",
64
+ 429 => "Too Many Requests",
65
+ 431 => "Request Header Fields Too Large",
66
+ 451 => "Unavailable For Legal Reasons",
67
+
68
+ 500 => "Internal Server Error",
69
+ 501 => "Not Implemented",
70
+ 502 => "Bad Gateway",
71
+ 503 => "Service Unavailable",
72
+ 504 => "Gateway Timeout",
73
+ 505 => "HTTP Version Not Supported",
74
+ 506 => "Variant Also Negotiates",
75
+ 507 => "Insufficient Storage",
76
+ 508 => "Loop Detected",
77
+ 510 => "Not Extended",
78
+ 511 => "Network Authentication Required",
79
+ }.freeze
80
+
81
+ # Look up the human-readable description for a status code.
82
+ # @parameter code [Integer] The HTTP status code.
83
+ # @returns [String | Nil] The standard description, if known.
84
+ def self.description(code)
85
+ return DESCRIPTIONS[code]
86
+ end
87
+ end
88
+ end
89
+ end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module HTTP
8
- VERSION = "0.67.0"
8
+ VERSION = "0.69.0"
9
9
  end
10
10
  end
data/lib/protocol/http.rb CHANGED
@@ -5,6 +5,7 @@
5
5
 
6
6
  require_relative "http/version"
7
7
 
8
+ require_relative "http/status"
8
9
  require_relative "http/headers"
9
10
  require_relative "http/request"
10
11
  require_relative "http/response"
data/readme.md CHANGED
@@ -30,6 +30,15 @@ Please see the [project documentation](https://socketry.github.io/protocol-http/
30
30
 
31
31
  Please see the [project releases](https://socketry.github.io/protocol-http/releases/index) for all releases.
32
32
 
33
+ ### v0.69.0
34
+
35
+ - Add `Protocol::HTTP::Body::Readable#to_io` for obtaining an IO-compatible stream adapter.
36
+ - Avoid creating an implicit buffered output for `Protocol::HTTP::Body::Stream`.
37
+
38
+ ### v0.68.0
39
+
40
+ - Add HTTP status descriptions.
41
+
33
42
  ### v0.67.0
34
43
 
35
44
  - Parse and resolve HTTP `Range` header values according to the default headers policy.
@@ -63,15 +72,6 @@ Please see the [project releases](https://socketry.github.io/protocol-http/relea
63
72
 
64
73
  - Expose `Protocol::HTTP::Body::Writable#count` attribute to provide access to the number of chunks written to the body.
65
74
 
66
- ### v0.59.0
67
-
68
- - Introduce `Protocol::HTTP::Middleware.load` method for loading middleware applications from files.
69
- - Prevent `ZLib::BufError` when deflating empty chunks by skipping deflation for empty chunks.
70
-
71
- ### v0.58.1
72
-
73
- - `Protocol::HTTP::DuplicateHeaderError` now includes the existing and new values for better debugging.
74
-
75
75
  ## See Also
76
76
 
77
77
  - [protocol-http1](https://github.com/socketry/protocol-http1) — HTTP/1 client/server implementation using this
data/releases.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Releases
2
2
 
3
+ ## v0.69.0
4
+
5
+ - Add `Protocol::HTTP::Body::Readable#to_io` for obtaining an IO-compatible stream adapter.
6
+ - Avoid creating an implicit buffered output for `Protocol::HTTP::Body::Stream`.
7
+
8
+ ## v0.68.0
9
+
10
+ - Add HTTP status descriptions.
11
+
3
12
  ## v0.67.0
4
13
 
5
14
  - Parse and resolve HTTP `Range` header values according to the default headers policy.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.67.0
4
+ version: 0.69.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -113,6 +113,7 @@ files:
113
113
  - lib/protocol/http/quoted_string.rb
114
114
  - lib/protocol/http/request.rb
115
115
  - lib/protocol/http/response.rb
116
+ - lib/protocol/http/status.rb
116
117
  - lib/protocol/http/version.rb
117
118
  - license.md
118
119
  - readme.md
metadata.gz.sig CHANGED
Binary file