Skip to content

Commit

Permalink
Merge pull request #134 from ethanis/master
Browse files Browse the repository at this point in the history
Add http reason phrase to cache
  • Loading branch information
garaujodev committed Apr 26, 2023
2 parents 3f1bf70 + 1bb0e7b commit 5408176
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/faraday/http_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ def create_response(env)
{
status: hash[:status],
body: hash[:body] || hash[:response_body],
response_headers: hash[:response_headers]
response_headers: hash[:response_headers],
reason_phrase: hash[:reason_phrase]
}
end

Expand Down
3 changes: 2 additions & 1 deletion lib/faraday/http_cache/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def serializable_hash
{
status: @payload[:status],
body: @payload[:body],
response_headers: @payload[:response_headers]
response_headers: @payload[:response_headers],
reason_phrase: @payload[:reason_phrase]
}
end

Expand Down
6 changes: 5 additions & 1 deletion spec/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
end

describe 'response unboxing' do
subject { described_class.new(status: 200, response_headers: {}, body: 'Hi!') }
subject { described_class.new(status: 200, response_headers: {}, body: 'Hi!', reason_phrase: 'Success') }

let(:env) { { method: :get } }
let(:response) { subject.to_response(env) }
Expand All @@ -224,6 +224,10 @@
it 'merges the body' do
expect(response.body).to eq('Hi!')
end

it 'merges the reason phrase' do
expect(response.reason_phrase).to eq('Success') if response.respond_to?(:reason_phrase)
end
end

describe 'remove age before caching and normalize max-age if non-zero age present' do
Expand Down

0 comments on commit 5408176

Please sign in to comment.