protocol-rack 0.13.0 → 0.14.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: b70faf13a5271971f02ddae3e19e17262c9df2ce74832cce7e0f6312265d76df
4
- data.tar.gz: e9a4a1dfc0cb419d6395a7e68300f270e26398fadb00661b08093c60b47b7ea2
3
+ metadata.gz: 9d3039968903e553afd725e0d5452f7d4b3975c9596b20ebbe2eeba354e83dba
4
+ data.tar.gz: 2b692f3676d057dc9c5b380bf13a5c1f79fc23df08f952b2a7b8d79786cb0713
5
5
  SHA512:
6
- metadata.gz: 1d8a7f11acb1220d0ed05626c4ddfb87ef23578922741e92d15bf32e0e0294c433ebfa2149e538f10352695b3c0cf30af69667ab34033beead13f799dbbbdad5
7
- data.tar.gz: 4d59623d81149838f7b2bf5f0ce67a13bdf39a0d5b04e17367ab6d07d57468d008834d6ad439cd6f41e42dcf95e6d314694334b38bfcfe02ba0d96f5a35b5def
6
+ metadata.gz: b839c48ff5275a8599c4cc98feb27501e4c84815d0945a9a78f239391cae24cbfb2eaf25142986deaccc6b95a184e6e4a9638d6634d210e02021388ddba3d172
7
+ data.tar.gz: f26a5aed151fcb2a253a36b9ffed7116665f8c16aac2d17523c6da3f5afc868331e038f2fd4c187e50fd21452cf2daacecbae376d4d80ce3832659f05b353fb6
checksums.yaml.gz.sig CHANGED
Binary file
@@ -6,7 +6,9 @@
6
6
  require_relative "body/streaming"
7
7
  require_relative "body/enumerable"
8
8
  require_relative "constants"
9
+
9
10
  require "protocol/http/body/completable"
11
+ require "protocol/http/body/head"
10
12
 
11
13
  module Protocol
12
14
  module Rack
@@ -37,8 +39,9 @@ module Protocol
37
39
  # @parameter headers [Hash] The response headers.
38
40
  # @parameter body [Object] The response body to wrap.
39
41
  # @parameter input [Object] Optional input for streaming bodies.
42
+ # @parameter head [Boolean] Indicates if this is a HEAD request, which should not have a body.
40
43
  # @returns [Protocol::HTTP::Body] The wrapped response body.
41
- def self.wrap(env, status, headers, body, input = nil)
44
+ def self.wrap(env, status, headers, body, input = nil, head = false)
42
45
  # In no circumstance do we want this header propagating out:
43
46
  if length = headers.delete(CONTENT_LENGTH)
44
47
  # We don't really trust the user to provide the right length to the transport.
@@ -84,6 +87,19 @@ module Protocol
84
87
  end
85
88
  end
86
89
 
90
+ # There are two main situations we need to handle:
91
+ # 1. The application has the `Rack::Head` middleware in the stack, which means we should not return a body, and the application is also responsible for setting the content-length header. `Rack::Head` will result in an empty enumerable body.
92
+ # 2. The application does not have `Rack::Head`, in which case it will return a body and we need to extract the length.
93
+ # In both cases, we need to ensure that the body is wrapped correctly. If there is no body and we don't know the length, we also just return `nil`.
94
+ if head
95
+ if body
96
+ body = ::Protocol::HTTP::Body::Head.for(body)
97
+ elsif length
98
+ body = ::Protocol::HTTP::Body::Head.new(length)
99
+ end
100
+ # Otherwise, body is `nil` and we don't know the length either.
101
+ end
102
+
87
103
  return body
88
104
  end
89
105
 
@@ -50,12 +50,7 @@ module Protocol
50
50
  body = hijack_body
51
51
  end
52
52
 
53
- body = Body.wrap(env, status, headers, body, request&.body)
54
-
55
- if request&.head?
56
- # I thought about doing this in Output.wrap, but decided the semantics are too tricky. Specifically, the various ways a rack response body can be wrapped, and the need to invoke #close at the right point.
57
- body = ::Protocol::HTTP::Body::Head.for(body)
58
- end
53
+ body = Body.wrap(env, status, headers, body, request&.body, request&.head?)
59
54
 
60
55
  protocol = meta[RACK_PROTOCOL]
61
56
 
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Protocol
7
7
  module Rack
8
- VERSION = "0.13.0"
8
+ VERSION = "0.14.0"
9
9
  end
10
10
  end
data/readme.md CHANGED
@@ -67,6 +67,10 @@ run proc{|env|
67
67
 
68
68
  Please see the [project releases](https://socketry.github.io/protocol-rack/releases/index) for all releases.
69
69
 
70
+ ### v0.14.0
71
+
72
+ - Handling of `HEAD` requests is now more robust.
73
+
70
74
  ### v0.13.0
71
75
 
72
76
  - 100% test and documentation coverage.
data/releases.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Releases
2
2
 
3
+ ## v0.14.0
4
+
5
+ - Handling of `HEAD` requests is now more robust.
6
+
3
7
  ## v0.13.0
4
8
 
5
9
  - 100% test and documentation coverage.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -38,7 +38,7 @@ cert_chain:
38
38
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
39
39
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
40
40
  -----END CERTIFICATE-----
41
- date: 2025-05-10 00:00:00.000000000 Z
41
+ date: 1980-01-02 00:00:00.000000000 Z
42
42
  dependencies:
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: protocol-http
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  requirements: []
114
- rubygems_version: 3.6.2
114
+ rubygems_version: 3.6.7
115
115
  specification_version: 4
116
116
  summary: An implementation of the Rack protocol/specification.
117
117
  test_files: []
metadata.gz.sig CHANGED
Binary file