Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add URL to to_hash in Faraday::Response (#1474) #1475

Merged
merged 2 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/faraday/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def success?
def to_hash
{
status: env.status, body: env.body,
response_headers: env.response_headers
response_headers: env.response_headers,
url: env.url
}
end

Expand Down
4 changes: 3 additions & 1 deletion spec/faraday/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
subject { Faraday::Response.new(env) }

let(:env) do
Faraday::Env.from(status: 404, body: 'yikes',
Faraday::Env.from(status: 404, body: 'yikes', url: Faraday::Utils.URI('https://lostisland.github.io/faraday'),
response_headers: { 'Content-Type' => 'text/plain' })
end

Expand All @@ -30,6 +30,7 @@
it { expect(hash[:status]).to eq(subject.status) }
it { expect(hash[:response_headers]).to eq(subject.headers) }
it { expect(hash[:body]).to eq(subject.body) }
it { expect(hash[:url]).to eq(subject.env.url) }
end

describe 'marshal serialization support' do
Expand All @@ -45,6 +46,7 @@
it { expect(loaded.env[:body]).to eq(env[:body]) }
it { expect(loaded.env[:response_headers]).to eq(env[:response_headers]) }
it { expect(loaded.env[:status]).to eq(env[:status]) }
it { expect(loaded.env[:url]).to eq(env[:url]) }
end

describe '#on_complete' do
Expand Down