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

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

Open
mikekelly opened this issue May 5, 2015 · 10 comments · May be fixed by #964
Open

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

mikekelly opened this issue May 5, 2015 · 10 comments · May be fixed by #964
Labels

Comments

@mikekelly
Copy link

WebMock is unable to correctly mock server responses that include underscores in the header names because it replaces any underscores with dashes. Is there a specific reason for this behaviour? I checked the HTTP specification and underscores are not an illegal character.

The offending line is here:

[name.to_s.split(/_|-/).map { |segment| segment.capitalize }.join("-"),

@bblimke
Copy link
Owner

bblimke commented May 7, 2015

@mikekelly WebMock tries to normalize headers to have unified version for comparison with stubs.

What exactly is the issue you have problems with?

@mikekelly
Copy link
Author

I'm stubbing a response which has a header called x-my_header but the webmock response renames it tox-my-header which breaks my client. I'm unable to simulate response headers with underscores

@bblimke
Copy link
Owner

bblimke commented May 7, 2015

@mikekelly I see. You're right, WebMock should not do that.

@mikekelly
Copy link
Author

Do you know why the behaviour was added in the first place?

@mikekelly
Copy link
Author

Do you need someone to propose a solution in a PR?

@mikekelly
Copy link
Author

Right now I am using a monkey patch which resolves this issue, I could re-use that.

@bblimke
Copy link
Owner

bblimke commented May 9, 2015

It was added to ensure unified format of headers i.e. if case someone declares 'content_type' in the response.

@bblimke
Copy link
Owner

bblimke commented May 9, 2015

It's wasn't the best approach though.

@davidbegin
Copy link
Collaborator

@mikekelly I made a pull request with some hacky code to get specs around how we are normalizing headers right now. Can you write a spec that fits you use case.

If you don't get to it, I'll take a stab when I have some time.
#482

@Blaze34
Copy link

Blaze34 commented Mar 10, 2017

It's a huge problem!!! My temporary solution:
/config/initializers/webmoch_rewrite.rb

# frozen_string_literal: true
if defined? WebMock::Response
  WebMock::Response.class_eval do
    def headers=(headers)
      @headers = headers
      if @headers && !@headers.is_a?(Proc) # rubocop:disable Style/GuardClause
        @headers =
          if @headers.key?(:skip_normalize)
            @headers.except(:skip_normalize)
          else
            WebMock::Util::Headers.normalize_headers(@headers)
          end
      end
    end
  end
end

wjordan referenced this issue in code-dot-org/code-dot-org Mar 13, 2018
- Use VCR to capture HTTP interactions for s3 integration tests.
- Use Timecop instead of sleep.
- Clean up shared-test boilerplate.
- Move AWS resource#to_a call outside of multithread block (attempt to resolve `JMESPath::Runtime#search` bug potentially caused by thread contention)
- replace Fakeweb with WebMock
@mvz mvz linked a pull request Jan 5, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants