protocol-http 0.58.1 → 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: e755c82bfe5d9098e7fe898dfb19e6963e500ab9410d9c7d04e2b6eb18886689
4
- data.tar.gz: 23717c1485024e2f324cc069f7684a924f864a9f57c2a6e62b7be72ba532db45
3
+ metadata.gz: e36f456a67fc57a222502502affe651c8f27d5b92b3a08918acfc8e5a8d54a1f
4
+ data.tar.gz: 465441e3c8c02f95c46a22147c4f7716d2db2927dd901ccb0b4f8aa00196741a
5
5
  SHA512:
6
- metadata.gz: a70c2c04344069a17fe6cdf1a5d23dcdaffcfbbfad815937d229c8bdeb7299bef0db2eb45c37e0fec6c1ba8cdf729560ebfcbb261910d630fc2d15d89a7b46a9
7
- data.tar.gz: fc047716362a83605223b9f0107a652ac8dcaa860c10815dd755c55a7ba73dc4a4ef468212d570e6c37340e6d7bfc3ba85ad6623c1620d38b2bbce57a9e3e4be
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
@@ -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
- 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.1"
8
+ VERSION = "0.59.0"
9
9
  end
10
10
  end
data/readme.md CHANGED
@@ -30,6 +30,11 @@ 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
+
33
38
  ### v0.58.1
34
39
 
35
40
  - `Protocol::HTTP::DuplicateHeaderError` now includes the existing and new values for better debugging.
@@ -85,10 +90,6 @@ Please see the [project releases](https://socketry.github.io/protocol-http/relea
85
90
  - `Protocol::HTTP::Headers#add` now coerces the value to a string when adding a header, ensuring consistent behaviour.
86
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.
87
92
 
88
- ### v0.50.0
89
-
90
- - Drop support for Ruby v3.1.
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,10 @@
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
+
3
8
  ## v0.58.1
4
9
 
5
10
  - `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.58.1
4
+ version: 0.59.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
Binary file