protocol-http 0.58.0 → 0.59.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: 971bece5e113d3f945faf8b8ce44858e97f0e6282e3a264b6e6fca1e57c8e71c
4
- data.tar.gz: 8d1139a2022dbe96710d7e0286a5c30c2384e14fcba3e0907428361b25c3a703
3
+ metadata.gz: e36f456a67fc57a222502502affe651c8f27d5b92b3a08918acfc8e5a8d54a1f
4
+ data.tar.gz: 465441e3c8c02f95c46a22147c4f7716d2db2927dd901ccb0b4f8aa00196741a
5
5
  SHA512:
6
- metadata.gz: 69d17f997389daf2332cacc0d5ac407897e2dc2a45c3e329f23dfc9b18f7075b425e10c43fff27ff1728f64e92a6843e3291be5103e9ee8c72d1f810c2603c01
7
- data.tar.gz: '09676f19f6b3bd4d6290b5dccd8f93d2c6409e82926fa74a9b21f39f4fa92df0d289ef8fac6b0460a9de2784d78d7114d262f9a5088f66518ef60b9d60a877f4'
6
+ metadata.gz: 887eff91a9b9ce7bbd7f7174029b34cb6b8039aa1dc4344d7eedc86dd398aec3bb81c16fd5d55d4e65b8175bba33baab785f2b8f4761a32d0c42be4c9d1eadf2
7
+ data.tar.gz: b276d08be05079a3f00a87fc2fccbf1a7e517c9621424fa8de0678707a5c7eda6049db03f28a2ce335202d95282fe5748148bd9b9b6e36051d133997301fb92b
checksums.yaml.gz.sig CHANGED
Binary file
@@ -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
- if chunk = super
117
- @input_length += chunk.bytesize
118
-
119
- chunk = @stream.deflate(chunk, Zlib::SYNC_FLUSH)
120
-
121
- @output_length += chunk.bytesize
122
-
123
- return chunk
124
- elsif !@stream.closed?
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
@@ -19,12 +19,33 @@ module Protocol
19
19
  include BadRequest
20
20
 
21
21
  # @parameter key [String] The header key that was duplicated.
22
- def initialize(key)
22
+ def initialize(key, existing_value, new_value)
23
23
  super("Duplicate singleton header key: #{key.inspect}")
24
+
25
+ @key = key
26
+ @existing_value = existing_value
27
+ @new_value = new_value
24
28
  end
25
29
 
26
30
  # @attribute [String] key The header key that was duplicated.
27
31
  attr :key
32
+
33
+ # @attribute [String] existing_value The existing value for the duplicated header.
34
+ attr :existing_value
35
+
36
+ # @attribute [String] new_value The new value for the duplicated header.
37
+ attr :new_value
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.
42
+ def detailed_message(highlight: false)
43
+ <<~MESSAGE
44
+ #{self.message}
45
+ Existing value: #{@existing_value.inspect}
46
+ New value: #{@new_value.inspect}
47
+ MESSAGE
48
+ end
28
49
  end
29
50
 
30
51
  # Raised when an invalid trailer header is encountered in headers.
@@ -453,7 +453,7 @@ module Protocol
453
453
  end
454
454
  else
455
455
  if hash.key?(key)
456
- raise DuplicateHeaderError, key
456
+ raise DuplicateHeaderError.new(key, hash[key], value)
457
457
  end
458
458
 
459
459
  hash[key] = value
@@ -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
- if block.arity == 0
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}}
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module HTTP
8
- VERSION = "0.58.0"
8
+ VERSION = "0.59.0"
9
9
  end
10
10
  end
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.59.0
34
+
35
+ - Introduce `Protocol::HTTP::Middleware.load` method for loading middleware applications from files.
36
+ - Prevent `ZLib::BufError` when deflating empty chunks by skipping deflation for empty chunks.
37
+
38
+ ### v0.58.1
39
+
40
+ - `Protocol::HTTP::DuplicateHeaderError` now includes the existing and new values for better debugging.
41
+
33
42
  ### v0.58.0
34
43
 
35
44
  - Move trailer validation to `Headers#add` method to ensure all additions are checked at the time of addition as this is a hard requirement.
@@ -81,14 +90,6 @@ Please see the [project releases](https://socketry.github.io/protocol-http/relea
81
90
  - `Protocol::HTTP::Headers#add` now coerces the value to a string when adding a header, ensuring consistent behaviour.
82
91
  - `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.
83
92
 
84
- ### v0.50.0
85
-
86
- - Drop support for Ruby v3.1.
87
-
88
- ### v0.48.0
89
-
90
- - Add support for parsing `accept`, `accept-charset`, `accept-encoding` and `accept-language` headers into structured values.
91
-
92
93
  ## See Also
93
94
 
94
95
  - [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.59.0
4
+
5
+ - Introduce `Protocol::HTTP::Middleware.load` method for loading middleware applications from files.
6
+ - Prevent `ZLib::BufError` when deflating empty chunks by skipping deflation for empty chunks.
7
+
8
+ ## v0.58.1
9
+
10
+ - `Protocol::HTTP::DuplicateHeaderError` now includes the existing and new values for better debugging.
11
+
3
12
  ## v0.58.0
4
13
 
5
14
  - Move trailer validation to `Headers#add` method to ensure all additions are checked at the time of addition as this is a hard requirement.
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.58.0
4
+ version: 0.59.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
Binary file