Add support for sending empty header values #132
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, there's not a super-easy way to pass a header with an empty value (e.g.,
X-Foo:
) in Typhoeus or Ethon. If an empty string is passed in as the header value, then currently the header is omitted from the request altogether. This is due to how curl historically treated empty values (see https://curl.haxx.se/mail/lib-2010-08/0174.html). Curl 7.23.0 (released November 2011) added a more standard way to pass empty values, but it requires special syntax of using a semicolon terminator.This changes Ethon's behavior, so that when an empty string is passed as the value of a header, it gets sent by curl as an empty HTTP header, rather than omitting the header. A nil value will still omit the header. This seems like a more intuitive approach to me, but this does make this a backwards incompatible change if you were relying on the previous empty string behavior. So if that seems problematic, let me know if you have any other ideas on how this should be handled, or if you don't think Ethon should handle this at all.
A few implementation notes:
EMPTY_STRING_VALUE
constant seems like the fastest approach (while.empty?
is marginally faster it becomes slower once you account for checking whether or not the value is a String).