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

Avoid failing on headers conflict #804

Closed
nfroidure opened this issue Jan 23, 2017 · 19 comments
Closed

Avoid failing on headers conflict #804

nfroidure opened this issue Jan 23, 2017 · 19 comments

Comments

@nfroidure
Copy link

The folowing error happen when a header has been set by the client library twice (one time in uppercase and another time in lower case. Failed to convert header keys to lower case due to field name conflict: {headerName}.

It is certainly a bad practice to do so but the fact is that nock is used mostly to mock external libraries calls so it would be useful to be able to disable error throwing for such cases with some options.

@felipead
Copy link

felipead commented Feb 9, 2017

Hi, I vote for this issue to be fixed. It's annoying me too when I use .defaultReplyHeaders. For example, if I define a nock as:

const scope = nock(URL, {encodedQueryParams: true})
    .defaultReplyHeaders({
      'Content-Type': 'application/json;charset=UTF-8'
    })

Then if I try to override the Content-Type for a specific test needs:

  scope
    .post('/login', `login=${USER}&password=${PASSWORD}`)
    .reply(200, '<login>ok</login>', [
      'Content-Type', 'application/xml',
      'Set-Cookie', 'JSESSIONID=foobar;Path=/foobar;Secure;HttpOnly'
    ])

I get the following error:

  Error: Failed to convert header keys to lower case due to field name conflict: content-type

The only solution is to convert all headers to lowercase. But nock should not require me to do this, it should be case insensitive.

@ianwsperber
Copy link
Contributor

@felipead Your example makes clear that this example is a bug/undesired. If you or @nfroidure are able to open a PR fixing this please do so. Otherwise I will try to get to when I have free time.

@ianwsperber ianwsperber added this to the 9.0.5 milestone Feb 9, 2017
@felipead
Copy link

felipead commented Feb 9, 2017

Thanks!

@ianwsperber ianwsperber self-assigned this Feb 9, 2017
@ianwsperber ianwsperber modified the milestones: 9.0.6, 9.0.5 Feb 10, 2017
@ianwsperber ianwsperber removed this from the 9.0.6 milestone Feb 27, 2017
@moaxaca
Copy link

moaxaca commented Mar 28, 2017

@ianwsperber Hey there appears to be an open PR, can you get the resolved?

@ianwsperber
Copy link
Contributor

@moaxaca Just left a comment on the PR! You can help get the PR merged faster if you could confirm whether it fixes the bug on your machine 😄

@moaxaca
Copy link

moaxaca commented Mar 28, 2017

@ianwsperber PR seems to works on my machine. 👍 I will dig into the change later tonight.

@ianwsperber
Copy link
Contributor

Thanks @moaxaca! Please comment on the PR when you have a chance.

@dcstone09
Copy link
Contributor

@ianwsperber @moaxaca The PR has been updated 👍

@moaxaca
Copy link

moaxaca commented Mar 29, 2017

@dcstone09 Sounds good pulling it in 40m to see if everything passes.

@felipead
Copy link

🎉

@CFreeAetna
Copy link

Any updates here?

@dcstone09
Copy link
Contributor

@CFreeAtEbsco I just updated the test, everything looks good to me.

@tedeh
Copy link

tedeh commented Feb 12, 2018

Why hasn't this been merged yet? It would appear to be a mostly harmless PR. Last given option should override earlier ones, like every other node library around.

@gr2m
Copy link
Member

gr2m commented Feb 12, 2018

@tedeh snarky comments won't get you anywhere. I understand your frustration, but please refrain from doing it on any open source project, ever <3

@gr2m gr2m closed this as completed in #862 Feb 12, 2018
@tedeh
Copy link

tedeh commented Feb 13, 2018

You are right and I'm sorry.

Is there anything in your opinion that prevents this from being merged as-is? Maybe I can help with the verification.

@gr2m
Copy link
Member

gr2m commented Feb 13, 2018

Thanks Tedde, it's already merged :)
#862

But the build failed so it's not released yet, if you could have a look at it that would be much appreciated: https://travis-ci.org/node-nock/nock/builds/340676385

@gkatsanos
Copy link

gkatsanos commented Aug 14, 2018

@gr2m is this released?

@RichardLitt
Copy link
Member

@gkatsanos Should have been! v9.1.7 got it. https://github.com/nock/nock/releases/tag/v9.1.7

@lock
Copy link

lock bot commented Sep 13, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it’s related. Thank you!

@lock lock bot locked as resolved and limited conversation to collaborators Sep 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants