Header not being returned when set in WithCallback #343

Closed
opened 2025-12-29 08:26:35 +01:00 by adam · 3 comments
Owner

Originally created by @GrantGHub on GitHub (Apr 15, 2021).

Originally assigned to: @StefH on GitHub.

Upgraded from 1.2.14 to 1.4.9. Was setting the header in WithCallback. This was correctly coming through. Now no headers are returned.

Taking the example tests and adjusting it (removing .WithHeader(header, "Stef");), should return the header set within WithCallback:

        public async Task Response_WithCallback_And_WithStatusCode_And_WithHeader()
        {
            // Assign
            var header = "X-UserId";
            var requestMessage = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", "::1");
            var responseBuilder = Response.Create()
                .WithCallback(request => new ResponseMessage
                {
                    BodyData = new BodyData
                    {
                        DetectedBodyType = BodyType.String,
                        BodyAsString = request.Path + "Bar"
                    },
                    StatusCode = HttpStatusCode.Accepted,
                    Headers = new Dictionary<string, WireMockList<string>>
                    {
                        { header, new WireMockList<string>("NA") }
                    }
                });

            // Act
            var response = await responseBuilder.ProvideResponseAsync(requestMessage, _settings);

            // Assert
            response.Message.BodyData.BodyAsString.Should().Be("/fooBar");
            response.Message.StatusCode.Should().Be(HttpStatusCode.Accepted);
            response.Message.Headers[header].Should().ContainSingle("NA");
        }

Headers are coming back empty.

response.Message.Headers.Count == 0
true

Originally created by @GrantGHub on GitHub (Apr 15, 2021). Originally assigned to: @StefH on GitHub. Upgraded from 1.2.14 to 1.4.9. Was setting the header in WithCallback. This was correctly coming through. Now no headers are returned. Taking the example tests and adjusting it (removing .WithHeader(header, "Stef");), should return the header set within WithCallback: ``` c# public async Task Response_WithCallback_And_WithStatusCode_And_WithHeader() { // Assign var header = "X-UserId"; var requestMessage = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", "::1"); var responseBuilder = Response.Create() .WithCallback(request => new ResponseMessage { BodyData = new BodyData { DetectedBodyType = BodyType.String, BodyAsString = request.Path + "Bar" }, StatusCode = HttpStatusCode.Accepted, Headers = new Dictionary<string, WireMockList<string>> { { header, new WireMockList<string>("NA") } } }); // Act var response = await responseBuilder.ProvideResponseAsync(requestMessage, _settings); // Assert response.Message.BodyData.BodyAsString.Should().Be("/fooBar"); response.Message.StatusCode.Should().Be(HttpStatusCode.Accepted); response.Message.Headers[header].Should().ContainSingle("NA"); } ``` Headers are coming back empty. `response.Message.Headers.Count == 0` true
adam added the bug label 2025-12-29 08:26:35 +01:00
adam closed this issue 2025-12-29 08:26:35 +01:00
Author
Owner

@StefH commented on GitHub (Apr 15, 2021):

@GrantGHub Thanks for finding this.

@StefH commented on GitHub (Apr 15, 2021): @GrantGHub Thanks for finding this.
Author
Owner

@StefH commented on GitHub (Apr 15, 2021):

https://github.com/WireMock-Net/WireMock.Net/pull/603

New version will be released shorty.

@StefH commented on GitHub (Apr 15, 2021): https://github.com/WireMock-Net/WireMock.Net/pull/603 New version will be released shorty.
Author
Owner

@GrantGHub commented on GitHub (Apr 16, 2021):

Thank you for such a fast turn around. I have retrieved the latest and confirm the issue has been resolved.

Thanks again for the responsiveness to this request. Appreciate it.

@GrantGHub commented on GitHub (Apr 16, 2021): Thank you for such a fast turn around. I have retrieved the latest and confirm the issue has been resolved. Thanks again for the responsiveness to this request. Appreciate it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#343