mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-12 05:20:35 +01:00
Is it possible to access custom headers inside callback? #495
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 @jamiemcl on GitHub (Feb 28, 2023).
Originally assigned to: @StefH on GitHub.
Hi,
I have a scenario where I need to match based on a specific header, and then retrieve the value of this header inside the WithCallback method. I can get this mock to match, however, when I try to access the value from request message headers, the header does not exist and I therefore cannot retrieve the value.
Is there anything I can do to retrieve the value of the x-test-id header here?
@StefH commented on GitHub (Feb 28, 2023):
Are you sure the request you send to WireMock.Net contains the
x-test-idheader?@jamiemcl commented on GitHub (Feb 28, 2023):
Thanks so much for the rapid reply!
Yes, I am sure that the request containers the header. As I mentioned, the issue isn’t with the mock not matching as the callback does get run with the above setup, but there are only 4 headers present on the requestMessage - none of which are my custom header but instead include Host and 3 others.
Any further thoughts?
@StefH commented on GitHub (Feb 28, 2023):
With this C# code:
And sending a GET to /random200or505
I get all headers back:

@jamiemcl commented on GitHub (Mar 1, 2023):
You are right, this is my mistake. I was adding the header to the initial request, which then subsequently made a second request inside of it. Sorry to waste your time, and thanks again for the prompt replies