Skip to content

Commit 5408176

Browse files
authored
Merge pull request #134 from ethanis/master
Add http reason phrase to cache
2 parents 3f1bf70 + 1bb0e7b commit 5408176

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

lib/faraday/http_cache.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ def create_response(env)
301301
{
302302
status: hash[:status],
303303
body: hash[:body] || hash[:response_body],
304-
response_headers: hash[:response_headers]
304+
response_headers: hash[:response_headers],
305+
reason_phrase: hash[:reason_phrase]
305306
}
306307
end
307308

lib/faraday/http_cache/response.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ def serializable_hash
142142
{
143143
status: @payload[:status],
144144
body: @payload[:body],
145-
response_headers: @payload[:response_headers]
145+
response_headers: @payload[:response_headers],
146+
reason_phrase: @payload[:reason_phrase]
146147
}
147148
end
148149

spec/response_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@
200200
end
201201

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

205205
let(:env) { { method: :get } }
206206
let(:response) { subject.to_response(env) }
@@ -224,6 +224,10 @@
224224
it 'merges the body' do
225225
expect(response.body).to eq('Hi!')
226226
end
227+
228+
it 'merges the reason phrase' do
229+
expect(response.reason_phrase).to eq('Success') if response.respond_to?(:reason_phrase)
230+
end
227231
end
228232

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

0 commit comments

Comments
 (0)