WireMock-Net / WireMock.Net

WireMock.Net is a flexible product for stubbing and mocking web HTTP responses using advanced request matching and response templating. Based on the functionality from http://WireMock.org, but extended with more functionality.
Apache License 2.0
1.39k stars 205 forks source link

Question: How to specify Transfer-Encoding response header? #137

Closed o7g8 closed 6 years ago

o7g8 commented 6 years ago

Hello,

I need to specify my own Transfer-Encoding response header as it's shown in the example below:

        [TestMethod]
        public async Task CheckMockHeaders() {
            var responseBody = @"<?xml version=""1.0""?><empty/>";
            mockServer
                .Given(Request
                    .Create()
                    .WithPath("/test")
                    .UsingPost())
                .RespondWith(Response
                    .Create()
                    .WithStatusCode(200)
                    .WithHeader("content-type", "text/xml")
                    .WithHeader("Content-Length", responseBody.Length.ToString())
                    .WithHeader("Transfer-Encoding", "identity")
                    .WithBody(responseBody));
            using (var httpClient = new HttpClient()) {
                var uri = mockServer.Urls.Single() + "test";
                using (var response = await httpClient.PostAsync(uri, new StringContent(""))) {
                    response.EnsureSuccessStatusCode();

                    var transferEncoding = response.Headers.SingleOrDefault(x => x.Key == "Transfer-Encoding");
                    Assert.IsNotNull(transferEncoding);
                    Assert.IsTrue(transferEncoding.Value.Contains("identity"));
                }
            }
        }

The last Assert fails, because the Transfer-Encoding is always chunked. Is it possible to override it?

WireMock.Net version 1.0.3.16.

StefH commented 6 years ago

Linked to #136

StefH commented 6 years ago

Solved, see NuGet 1.0.3.18

GMPrakhar commented 3 years ago

I am seeing this issue again.. Transfer-encoding always goes as chunked when used with WithBodyFromFile

gorillapower commented 1 year ago

I am seeing this issue too, the Transfer-Encoding header should be allowed to contain multiple values, as long as the last value is chunked, then it should be valid as a chunked request.

image

https://www.rfc-editor.org/rfc/rfc9112#section-6.1-4:~:text=If%20any%20transfer%20coding%20other%20than%20chunked%20is%20applied%20to%20a%20response%27s%20content%2C%20the%20sender%20MUST%20either%20apply%20chunked%20as%20the%20final%20transfer%20coding%20or%20terminate%20the%20message%20by%20closing%20the%20connection.