Skip to content

Replace, rather than append headers #9

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

drewish
Copy link

@drewish drewish commented Sep 4, 2018

I was trying to set an XML Accept header but the server was seeing it as HTML. It looks like the issue is using add_field since it:

Adds a value to a named header field, instead of replacing its value.

I think we'd actually want to be using the hash syntax to replace the values since Paw seems to merge multiple headers into one value.

You can see the issue using output of the current code:

require 'net/http'
require 'net/https'

uri = URI('https://echo.paw.cloud/')

# Create client
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER

# Create Request
req =  Net::HTTP::Get.new(uri)
# Add headers
req.add_field "Accept", "application/xml"

puts req["accept"]

Will output: */*, application/xml

This version should output something more like:

require 'net/http'
require 'net/https'

uri = URI('https://echo.paw.cloud/')

# Create client
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER

# Create Request
req =  Net::HTTP::Get.new(uri)
# Add headers
req["Accept"] = "application/xml"

puts req["accept"]

Will output: application/xml

@@ -57,9 +57,9 @@ def send_request
req = Net::HTTP::{{{method}}}{{#body.has_multipart_body}}::Multipart{{/body.has_multipart_body}}.new(uri{{#body.has_multipart_body}}, body{{/body.has_multipart_body}})
{{! ----- }}
{{#headers.has_headers}}
{{#headers.header_list}}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this down so we only output the comment once for the entire list of headers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant