mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 14:20:29 +01:00
Issue with matching when client uses Host header #256
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @bellorap on GitHub (Mar 9, 2020).
I'd like to integration test an application that uses the
Hostheader in calls to its dependencies. I'm trying to use WireMock to stub these API dependencies, but the existence of theHostheader is causing the mapping not to match. Here's an example of the problem using NUnit and Flurl:Test_WithoutHostHeadersucceeds whileTest_WithHostHeaderthrows the following:Likewise, curling from the command line during test execution shows a similar outcome:
Is there a workaround to this problem? Or do I need to refactor my application to not use the
Hostheader during integration tests?I'm using WireMock.Net version
1.1.10.@StefH commented on GitHub (Mar 9, 2020):
You can just use
WithHeader?Like
@bellorap commented on GitHub (Mar 9, 2020):
Hi @StefH, thanks for the quick response. No, unfortunately adding
WithHeader("Host", "*")still results in the 404 from the test case with the Host header.@bellorap commented on GitHub (Mar 9, 2020):
Hi @StefH, thanks to your example I believe I narrowed down the problem to
WithUrlFor example, this solution works:
While this doesn't:
Am I using
WithUrlcorrectly? In practice, I think I need it to match requests to different ports with different mappings.@StefH commented on GitHub (Mar 9, 2020):
WithUrl can be used. However in your case I think that removing WithUrl and/or replacing with WithPath would be better.
Take a look at the Wiki or unit tests for more examples.
@bellorap commented on GitHub (Mar 9, 2020):
@StefH I'm not sure I understand your answer. Is the last snipped posted above expected to work? If not, can you please explain why? Otherwise, would it make sense to open a bug for this behavior?
@StefH commented on GitHub (Mar 10, 2020):
The
WithUrlworks as expected. However, because you overwrite the host, the url in WireMock is changed to that one.So you need code like this:
Note that adding the console logger and setting AllowPartialMapping = true can help you detect why a mapping is not 100% matching.
@bellorap commented on GitHub (Mar 11, 2020):
@StefH That makes sense, thanks for explaining! I also didn't notice
AllowPartialMapping- that's helpful!