Skip to content

Commit

Permalink
Re-added TRANSFER_ENCODING as not in Rack 1
Browse files Browse the repository at this point in the history
  • Loading branch information
schinery committed Oct 24, 2023
1 parent eb6828b commit ff8c51a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/grape/dsl/inside_route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def stream(value = nil)
return if value.nil? && @stream.nil?

header Rack::CONTENT_LENGTH, nil
header Rack::TRANSFER_ENCODING, nil
header Grape::Http::Headers::TRANSFER_ENCODING, nil
header Rack::CACHE_CONTROL, 'no-cache' # Skips ETag generation (reading the response up front)
if value.is_a?(String)
file_body = Grape::ServeStream::FileBody.new(value)
Expand Down
14 changes: 8 additions & 6 deletions lib/grape/http/headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ module Headers
QUERY_STRING = 'QUERY_STRING'

if Grape.lowercase_headers?
ALLOW = 'allow'
LOCATION = 'location'
X_CASCADE = 'x-cascade'
ALLOW = 'allow'
LOCATION = 'location'
TRANSFER_ENCODING = 'transfer-encoding'
X_CASCADE = 'x-cascade'
else
ALLOW = 'Allow'
LOCATION = 'Location'
X_CASCADE = 'X-Cascade'
ALLOW = 'Allow'
LOCATION = 'Location'
TRANSFER_ENCODING = 'Transfer-Encoding'
X_CASCADE = 'X-Cascade'
end

GET = 'GET'
Expand Down
2 changes: 1 addition & 1 deletion spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ class DummyFormatClass
expect(last_response.headers[Rack::CONTENT_TYPE]).to eq('text/plain')
expect(last_response.headers[Rack::CONTENT_LENGTH]).to be_nil
expect(last_response.headers[Rack::CACHE_CONTROL]).to eq('no-cache')
expect(last_response.headers[Rack::TRANSFER_ENCODING]).to eq('chunked')
expect(last_response.headers[Grape::Http::Headers::TRANSFER_ENCODING]).to eq('chunked')

expect(last_response.body).to eq("c\r\nThis is some\r\nd\r\n file content\r\n0\r\n\r\n")
end
Expand Down
12 changes: 6 additions & 6 deletions spec/grape/dsl/inside_route_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def initialize
before do
subject.header Rack::CACHE_CONTROL, 'cache'
subject.header Rack::CONTENT_LENGTH, 123
subject.header Rack::TRANSFER_ENCODING, 'base64'
subject.header Grape::Http::Headers::TRANSFER_ENCODING, 'base64'
end

it 'sends no deprecation warnings' do
Expand Down Expand Up @@ -295,7 +295,7 @@ def initialize
it 'does not change the Transfer-Encoding header' do
subject.sendfile file_path

expect(subject.header[Rack::TRANSFER_ENCODING]).to eq 'base64'
expect(subject.header[Grape::Http::Headers::TRANSFER_ENCODING]).to eq 'base64'
end
end

Expand Down Expand Up @@ -326,7 +326,7 @@ def initialize
before do
subject.header Rack::CACHE_CONTROL, 'cache'
subject.header Rack::CONTENT_LENGTH, 123
subject.header Rack::TRANSFER_ENCODING, 'base64'
subject.header Grape::Http::Headers::TRANSFER_ENCODING, 'base64'
end

it 'emits no deprecation warnings' do
Expand Down Expand Up @@ -362,7 +362,7 @@ def initialize
it 'sets Transfer-Encoding header to nil' do
subject.stream file_path

expect(subject.header[Rack::TRANSFER_ENCODING]).to be_nil
expect(subject.header[Grape::Http::Headers::TRANSFER_ENCODING]).to be_nil
end
end

Expand All @@ -376,7 +376,7 @@ def initialize
before do
subject.header Rack::CACHE_CONTROL, 'cache'
subject.header Rack::CONTENT_LENGTH, 123
subject.header Rack::TRANSFER_ENCODING, 'base64'
subject.header Grape::Http::Headers::TRANSFER_ENCODING, 'base64'
end

it 'emits no deprecation warnings' do
Expand Down Expand Up @@ -406,7 +406,7 @@ def initialize
it 'sets Transfer-Encoding header to nil' do
subject.stream stream_object

expect(subject.header[Rack::TRANSFER_ENCODING]).to be_nil
expect(subject.header[Grape::Http::Headers::TRANSFER_ENCODING]).to be_nil
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/integration/rack/v2/headers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
describe Grape::Http::Headers do
it { expect(described_class::ALLOW).to eq('Allow') }
it { expect(described_class::LOCATION).to eq('Location') }
it { expect(described_class::TRANSFER_ENCODING).to eq('Transfer-Encoding') }
it { expect(described_class::X_CASCADE).to eq('X-Cascade') }
end
1 change: 1 addition & 0 deletions spec/integration/rack/v3/headers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
describe Grape::Http::Headers do
it { expect(described_class::ALLOW).to eq('allow') }
it { expect(described_class::LOCATION).to eq('location') }
it { expect(described_class::TRANSFER_ENCODING).to eq('transfer-encoding') }
it { expect(described_class::X_CASCADE).to eq('x-cascade') }
end

0 comments on commit ff8c51a

Please sign in to comment.