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

Closed
opened 2025-12-29 08:22:18 +01:00 by adam · 4 comments
Owner

Originally created by @o7g8 on GitHub (May 16, 2018).

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.

Originally created by @o7g8 on GitHub (May 16, 2018). Hello, I need to specify my own `Transfer-Encoding` response header as it's shown in the example below: ```csharp [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`.
adam closed this issue 2025-12-29 08:22:18 +01:00
Author
Owner

@StefH commented on GitHub (May 16, 2018):

Linked to #136

@StefH commented on GitHub (May 16, 2018): Linked to #136
Author
Owner

@StefH commented on GitHub (May 25, 2018):

Solved, see NuGet 1.0.3.18

@StefH commented on GitHub (May 25, 2018): Solved, see NuGet 1.0.3.18
Author
Owner

@GMPrakhar commented on GitHub (Jan 15, 2021):

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

@GMPrakhar commented on GitHub (Jan 15, 2021): I am seeing this issue again.. Transfer-encoding always goes as chunked when used with WithBodyFromFile
Author
Owner

@gorillapower commented on GitHub (Apr 17, 2023):

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.

@gorillapower commented on GitHub (Apr 17, 2023): 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://user-images.githubusercontent.com/8879065/232445053-167acda6-f779-4178-aec0-eb75ce394a6f.png) 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#101