-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix #2403 * Fix #2404 Replace last_response.headers[Rack::CONTENT_TYPE] by last_response.content_type Replace last_response.headers['Location'] by last_response.content_type Replace last_response.headers[Rack::CONTENT_LENGTH] by last_response.content_type * Add CHANGELOG.md entry * Fix rubocop * Update CHANGELOG.md * Remove Rack::Chunked deprecation
- Loading branch information
1 parent
10944de
commit 6888ad6
Showing
8 changed files
with
110 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'base64' | ||
|
||
module Spec | ||
module Support | ||
module Helpers | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# frozen_string_literal: true | ||
|
||
# this is a copy of Rack::Chunked which has been removed in rack > 3.0 | ||
|
||
class ChunkedResponse | ||
class Body | ||
TERM = "\r\n" | ||
TAIL = "0#{TERM}" | ||
|
||
# Store the response body to be chunked. | ||
def initialize(body) | ||
@body = body | ||
end | ||
|
||
# For each element yielded by the response body, yield | ||
# the element in chunked encoding. | ||
def each(&block) | ||
term = TERM | ||
@body.each do |chunk| | ||
size = chunk.bytesize | ||
next if size == 0 | ||
|
||
yield [size.to_s(16), term, chunk.b, term].join | ||
end | ||
yield TAIL | ||
yield_trailers(&block) | ||
yield term | ||
end | ||
|
||
# Close the response body if the response body supports it. | ||
def close | ||
@body.close if @body.respond_to?(:close) | ||
end | ||
|
||
private | ||
|
||
# Do nothing as this class does not support trailer headers. | ||
def yield_trailers; end | ||
end | ||
|
||
class TrailerBody < Body | ||
private | ||
|
||
# Yield strings for each trailer header. | ||
def yield_trailers | ||
@body.trailers.each_pair do |k, v| | ||
yield "#{k}: #{v}\r\n" | ||
end | ||
end | ||
end | ||
|
||
def initialize(app) | ||
@app = app | ||
end | ||
|
||
def call(env) | ||
status, headers, body = response = @app.call(env) | ||
|
||
if !Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.key?(status.to_i) && | ||
!headers[Rack::CONTENT_LENGTH] && | ||
!headers[Rack::TRANSFER_ENCODING] | ||
|
||
headers[Rack::TRANSFER_ENCODING] = 'chunked' | ||
response[2] = if headers['trailer'] | ||
TrailerBody.new(body) | ||
else | ||
Body.new(body) | ||
end | ||
end | ||
|
||
response | ||
end | ||
end |