protocol-http 0.58.1 → 0.60.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/context/headers.md +2 -2
- data/lib/protocol/http/body/deflate.rb +14 -10
- data/lib/protocol/http/body/writable.rb +4 -1
- data/lib/protocol/http/error.rb +4 -1
- data/lib/protocol/http/header/generic.rb +1 -1
- data/lib/protocol/http/middleware/builder.rb +38 -7
- data/lib/protocol/http/version.rb +2 -2
- data/readme.md +9 -10
- data/releases.md +9 -0
- data.tar.gz.sig +0 -0
- metadata +2 -2
- 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: 86fc99bdf4478ab27c254aaf2c08879a76a7179d2f05979c022d7d9dd4149f7f
|
|
4
|
+
data.tar.gz: ef2431fbfddafb860028590fd5bfe641b3b7261e7beed8d5cdefea202b1423f6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4169ced46a030ec0d90e4ae0711dabd4663ddc7f1c51a5f8687a3eee30d23754df5c537f19533d350681f03196403e3501bd568d3c3526c465c5760ca2939fce
|
|
7
|
+
data.tar.gz: 88f2b94a09f2ce2c9b3815e609056d7ae45c4e657455abc48073d5f6b61aca6ae4d6dd3ad7104a0e576abfdea1c7fff2f5f838ba11fa398ed40c041bc913f6c8
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/context/headers.md
CHANGED
|
@@ -63,8 +63,8 @@ HTTP trailers are headers that appear after the message body. For security reaso
|
|
|
63
63
|
```ruby
|
|
64
64
|
# Working with trailers
|
|
65
65
|
headers = Protocol::HTTP::Headers.new([
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
["content-type", "text/html"],
|
|
67
|
+
["content-length", "1000"]
|
|
68
68
|
])
|
|
69
69
|
|
|
70
70
|
# Start trailer section
|
|
@@ -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-2026, by Samuel Williams.
|
|
5
5
|
|
|
6
6
|
require_relative "wrapper"
|
|
7
7
|
|
|
@@ -113,15 +113,19 @@ module Protocol
|
|
|
113
113
|
return if @stream.finished?
|
|
114
114
|
|
|
115
115
|
# The stream might have been closed while waiting for the chunk to come in.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
116
|
+
while chunk = super
|
|
117
|
+
unless chunk.empty?
|
|
118
|
+
@input_length += chunk.bytesize
|
|
119
|
+
|
|
120
|
+
chunk = @stream.deflate(chunk, Zlib::SYNC_FLUSH)
|
|
121
|
+
|
|
122
|
+
@output_length += chunk.bytesize
|
|
123
|
+
|
|
124
|
+
return chunk
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
if !@stream.closed?
|
|
125
129
|
chunk = @stream.finish
|
|
126
130
|
|
|
127
131
|
@output_length += chunk.bytesize
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# Released under the MIT License.
|
|
4
|
-
# Copyright, 2024-
|
|
4
|
+
# Copyright, 2024-2026, by Samuel Williams.
|
|
5
5
|
|
|
6
6
|
require_relative "readable"
|
|
7
7
|
|
|
@@ -28,6 +28,9 @@ module Protocol
|
|
|
28
28
|
# @attribute [Integer] The length of the response body if known.
|
|
29
29
|
attr :length
|
|
30
30
|
|
|
31
|
+
# @attribute [Integer] The number of chunks written to the body.
|
|
32
|
+
attr :count
|
|
33
|
+
|
|
31
34
|
# Stop generating output; cause the next call to write to fail with the given error. Does not prevent existing chunks from being read. In other words, this indicates both that no more data will be or should be written to the body.
|
|
32
35
|
#
|
|
33
36
|
# @parameter error [Exception] The error that caused this body to be closed, if any. Will be raised on the next call to {read}.
|
data/lib/protocol/http/error.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# Released under the MIT License.
|
|
4
|
-
# Copyright, 2018-
|
|
4
|
+
# Copyright, 2018-2026, by Samuel Williams.
|
|
5
5
|
|
|
6
6
|
module Protocol
|
|
7
7
|
module HTTP
|
|
@@ -36,6 +36,9 @@ module Protocol
|
|
|
36
36
|
# @attribute [String] new_value The new value for the duplicated header.
|
|
37
37
|
attr :new_value
|
|
38
38
|
|
|
39
|
+
# Provides a detailed error message including the existing and new values.
|
|
40
|
+
# @parameter highlight [Boolean] Whether to highlight the message (not currently used).
|
|
41
|
+
# @return [String] The detailed error message.
|
|
39
42
|
def detailed_message(highlight: false)
|
|
40
43
|
<<~MESSAGE
|
|
41
44
|
#{self.message}
|
|
@@ -18,6 +18,22 @@ module Protocol
|
|
|
18
18
|
@app = default_app
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
# Build the middleware application using the given block.
|
|
22
|
+
#
|
|
23
|
+
# @parameter block [Proc] The block to pass to the middleware constructor.
|
|
24
|
+
# @returns [Builder] The builder.
|
|
25
|
+
def build(&block)
|
|
26
|
+
if block_given?
|
|
27
|
+
if block.arity == 0
|
|
28
|
+
instance_exec(&block)
|
|
29
|
+
else
|
|
30
|
+
yield self
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
return self
|
|
35
|
+
end
|
|
36
|
+
|
|
21
37
|
# Use the given middleware with the given arguments and options.
|
|
22
38
|
#
|
|
23
39
|
# @parameter middleware [Class | Object] The middleware class to use.
|
|
@@ -44,15 +60,28 @@ module Protocol
|
|
|
44
60
|
end
|
|
45
61
|
|
|
46
62
|
# Build a middleware application using the given block.
|
|
47
|
-
def self.build(&block)
|
|
48
|
-
builder = Builder.new
|
|
63
|
+
def self.build(*arguments, &block)
|
|
64
|
+
builder = Builder.new(*arguments)
|
|
65
|
+
|
|
66
|
+
builder.build(&block)
|
|
67
|
+
|
|
68
|
+
return builder.to_app
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Load a middleware application from the given path.
|
|
72
|
+
#
|
|
73
|
+
# @parameter path [String] The path to the middleware application.
|
|
74
|
+
# @parameter arguments [Array] The arguments to pass to the middleware constructor.
|
|
75
|
+
# @parameter options [Hash] The options to pass to the middleware constructor.
|
|
76
|
+
# @parameter block [Proc] The block to pass to the middleware constructor.
|
|
77
|
+
def self.load(path, *arguments, &block)
|
|
78
|
+
builder = Builder.new(*arguments)
|
|
79
|
+
|
|
80
|
+
binding = Builder::TOPLEVEL_BINDING.call(builder)
|
|
81
|
+
eval(File.read(path), binding, path)
|
|
49
82
|
|
|
50
83
|
if block_given?
|
|
51
|
-
|
|
52
|
-
builder.instance_exec(&block)
|
|
53
|
-
else
|
|
54
|
-
yield builder
|
|
55
|
-
end
|
|
84
|
+
builder.build(&block)
|
|
56
85
|
end
|
|
57
86
|
|
|
58
87
|
return builder.to_app
|
|
@@ -60,3 +89,5 @@ module Protocol
|
|
|
60
89
|
end
|
|
61
90
|
end
|
|
62
91
|
end
|
|
92
|
+
|
|
93
|
+
Protocol::HTTP::Middleware::Builder::TOPLEVEL_BINDING = ->(builder){builder.instance_eval{binding}}
|
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.60.0
|
|
34
|
+
|
|
35
|
+
- Expose `Protocol::HTTP::Body::Writable#count` attribute to provide access to the number of chunks written to the body.
|
|
36
|
+
|
|
37
|
+
### v0.59.0
|
|
38
|
+
|
|
39
|
+
- Introduce `Protocol::HTTP::Middleware.load` method for loading middleware applications from files.
|
|
40
|
+
- Prevent `ZLib::BufError` when deflating empty chunks by skipping deflation for empty chunks.
|
|
41
|
+
|
|
33
42
|
### v0.58.1
|
|
34
43
|
|
|
35
44
|
- `Protocol::HTTP::DuplicateHeaderError` now includes the existing and new values for better debugging.
|
|
@@ -79,16 +88,6 @@ Please see the [project releases](https://socketry.github.io/protocol-http/relea
|
|
|
79
88
|
- Expose `tail` in `Headers.new` so that trailers can be accurately reproduced.
|
|
80
89
|
- Add agent context.
|
|
81
90
|
|
|
82
|
-
### v0.51.0
|
|
83
|
-
|
|
84
|
-
- `Protocol::HTTP::Headers` now raise a `DuplicateHeaderError` when a duplicate singleton header (e.g. `content-length`) is added.
|
|
85
|
-
- `Protocol::HTTP::Headers#add` now coerces the value to a string when adding a header, ensuring consistent behaviour.
|
|
86
|
-
- `Protocol::HTTP::Body::Head.for` now accepts an optional `length` parameter, allowing it to create a head body even when the body is not provided, based on the known content length.
|
|
87
|
-
|
|
88
|
-
### v0.50.0
|
|
89
|
-
|
|
90
|
-
- Drop support for Ruby v3.1.
|
|
91
|
-
|
|
92
91
|
## See Also
|
|
93
92
|
|
|
94
93
|
- [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.60.0
|
|
4
|
+
|
|
5
|
+
- Expose `Protocol::HTTP::Body::Writable#count` attribute to provide access to the number of chunks written to the body.
|
|
6
|
+
|
|
7
|
+
## v0.59.0
|
|
8
|
+
|
|
9
|
+
- Introduce `Protocol::HTTP::Middleware.load` method for loading middleware applications from files.
|
|
10
|
+
- Prevent `ZLib::BufError` when deflating empty chunks by skipping deflation for empty chunks.
|
|
11
|
+
|
|
3
12
|
## v0.58.1
|
|
4
13
|
|
|
5
14
|
- `Protocol::HTTP::DuplicateHeaderError` now includes the existing and new values for better debugging.
|
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.
|
|
4
|
+
version: 0.60.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Samuel Williams
|
|
@@ -128,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
128
128
|
requirements:
|
|
129
129
|
- - ">="
|
|
130
130
|
- !ruby/object:Gem::Version
|
|
131
|
-
version: '3.
|
|
131
|
+
version: '3.3'
|
|
132
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
133
|
requirements:
|
|
134
134
|
- - ">="
|
metadata.gz.sig
CHANGED
|
Binary file
|