Skip to content

Keep underscores when normalizing headers#964

Open
mvz wants to merge 1 commit into
bblimke:masterfrom
mvz:fix-header-underscore-handling
Open

Keep underscores when normalizing headers#964
mvz wants to merge 1 commit into
bblimke:masterfrom
mvz:fix-header-underscore-handling

Conversation

@mvz

@mvz mvz commented Jan 5, 2022

Copy link
Copy Markdown

Some servers distinguish underscores from dashes in request headers. To allow users to test that the correct character is used, checking the sent headers should make the same distinction.

With this change, webmock no longer normalizes underscores to dashes for headers defined using strings.

Since symbols are commonly used with underscores to specify headers that use dashes, headers specified with symbol keys are still normalized to dashes.

Fixes #474.

Some servers distinguish underscores from dashes in request headers. To
allow users to test that the correct character is used, checking the
sent headers should make the same distinction.

With this change, webmock no longer normalizes underscores to dashes for
headers defined using strings.

Since symbols are commonly used with underscores to specify headers that
use dashes, headers specified with symbol keys are still normalized to
dashes.
@bblimke

bblimke commented Jan 6, 2022

Copy link
Copy Markdown
Owner

@mvz thank you for the PR. I'm not sure about the new logic though. It has a different behaviour for symbols than strings based on assumption "commonly used with underscores" yet strings are not.

I think the behaviour should be unified and deterministic for every case.

Change like that will require a major version bump anyway.

I'm keen to stop normalizing headers completely, do a major version bump, yet have a way of headers matching,
that has a mapping of acceptable common symbols used for some headers. E.g. :content_type => 'Content-Type'
That mapping could be extended by developers.

@mvz

mvz commented Jan 7, 2022

Copy link
Copy Markdown
Author

It has a different behaviour for symbols than strings based on assumption "commonly used with underscores" yet strings are not.

Yes, that is on purpose since symbols with dashes are harder to write so many developers will probably have symbols used like that. However, I'm all for being more strict here and just unifying the behavior.

In fact, given #863 (comment), normalization could then become just a simple .downcase on the stringified key.

Change like that will require a major version bump anyway.

To make this smoother, this could also be introduced as an optional change controlled by a setting. The old behavior can than be removed with a major version bump later.

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.

WebMock::Util::Headers.normalize_headers replaces underscores with dashes

2 participants