Add support for compressed requests, such as GZIP or DEFLATE #252

Closed
opened 2025-12-29 08:24:46 +01:00 by adam · 13 comments
Owner

Originally created by @ezarko on GitHub (Feb 21, 2020).

I did a quick search in the code and see an HttpClient with these settings, but I am assuming that is used by the proxy. Can the server itself handle an incoming request with has been GZIP'd?

Originally created by @ezarko on GitHub (Feb 21, 2020). I did a quick search in the code and see an HttpClient with these settings, but I am assuming that is used by the proxy. Can the server itself handle an incoming request with has been GZIP'd?
adam added the feature label 2025-12-29 08:24:46 +01:00
adam closed this issue 2025-12-29 08:24:46 +01:00
Author
Owner

@ezarko commented on GitHub (Feb 25, 2020):

So an issue which we were having was resolved when we stopped sending it GZIP'd, so I guess that is the answer. Can we add support for GZIP/Deflate to the server?

@ezarko commented on GitHub (Feb 25, 2020): So an issue which we were having was resolved when we stopped sending it GZIP'd, so I guess that is the answer. Can we add support for GZIP/Deflate to the server?
Author
Owner

@StefH commented on GitHub (Feb 25, 2020):

  1. HttpClient is only used for Proxying
  2. You can create a PR to support GZIP/Deflate ? (I'm not sure if this functionality is out-of-the box for Owin/Kestrel and net452 / net46 / net core). Or that some helper code is needed like https://github.com/mikegore1000/SqueezeMe
@StefH commented on GitHub (Feb 25, 2020): 1. HttpClient is only used for Proxying 2. You can create a PR to support GZIP/Deflate ? (I'm not sure if this functionality is out-of-the box for Owin/Kestrel and net452 / net46 / net core). Or that some helper code is needed like https://github.com/mikegore1000/SqueezeMe
Author
Owner

@ezarko commented on GitHub (Feb 25, 2020):

I took a swing at it and created https://github.com/WireMock-Net/WireMock.Net/pull/430. I decided to let CI build it for me. Let's see what we get.

@ezarko commented on GitHub (Feb 25, 2020): I took a swing at it and created https://github.com/WireMock-Net/WireMock.Net/pull/430. I decided to let CI build it for me. Let's see what we get.
Author
Owner

@ezarko commented on GitHub (Mar 12, 2020):

So I tried this in https://github.com/WireMock-Net/WireMock.Net/pull/430 ... The issue that I ran into has to do with framework version compatibility. I have the more or less correct approach, but it needs a little dedicated hand holding.

@ezarko commented on GitHub (Mar 12, 2020): So I tried this in https://github.com/WireMock-Net/WireMock.Net/pull/430 ... The issue that I ran into has to do with framework version compatibility. I have the more or less correct approach, but it needs a little dedicated hand holding.
Author
Owner

@StefH commented on GitHub (Mar 13, 2020):

I think it's easier to just view the Content-Encoding header and decide to automatically decompress this bytes in the BodyParser.cs file.

I'll take a look.

@StefH commented on GitHub (Mar 13, 2020): I think it's easier to just view the `Content-Encoding` header and decide to automatically decompress this bytes in the BodyParser.cs file. I'll take a look.
Author
Owner

@StefH commented on GitHub (Mar 14, 2020):

@ezarko Can you try preview version on MyGet : WireMock.Net.1.1.10-ci-12887 ? This version should support gzip and deflate in the request

@StefH commented on GitHub (Mar 14, 2020): @ezarko Can you try preview version on MyGet : `WireMock.Net.1.1.10-ci-12887` ? This version should support gzip and deflate in the request
Author
Owner

@StefH commented on GitHub (Mar 19, 2020):

@ezarko Did you have time to test this new version?
See https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

@StefH commented on GitHub (Mar 19, 2020): @ezarko Did you have time to test this new version? See https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
Author
Owner

@StefH commented on GitHub (Mar 25, 2020):

@ezarko Can you please test if this works for you?

@StefH commented on GitHub (Mar 25, 2020): @ezarko Can you please test if this works for you?
Author
Owner

@StefH commented on GitHub (Apr 1, 2020):

@ezarko Can you please test if this works for you?

@StefH commented on GitHub (Apr 1, 2020): @ezarko Can you please test if this works for you?
Author
Owner

@StefH commented on GitHub (Apr 8, 2020):

Hello @ezarko , did you have time yet to test this ?

@StefH commented on GitHub (Apr 8, 2020): Hello @ezarko , did you have time yet to test this ?
Author
Owner

@ezarko commented on GitHub (Apr 10, 2020):

@StefH sorry for taking so long to get back to you. If you can provide a Docker image, or give me instructions on how to build one myself using the preview version, I can get this tested next week.

Alternatively I can see about creating a test for it, if that helps. It should be as simple as:

echo ‘{“foo”:”bar”}’ | gzip -c | curl -H’Content-Type: application/json’ -H’Content-Encoding: Gzip’ --data-binary @-

Or you could prepare a gzip-ed file and put it in a test class as an array of bytes or whatever.

@ezarko commented on GitHub (Apr 10, 2020): @StefH sorry for taking so long to get back to you. If you can provide a Docker image, or give me instructions on how to build one myself using the preview version, I can get this tested next week. Alternatively I can see about creating a test for it, if that helps. It should be as simple as: echo ‘{“foo”:”bar”}’ | gzip -c | curl -H’Content-Type: application/json’ -H’Content-Encoding: Gzip’ --data-binary @- <url> Or you could prepare a gzip-ed file and put it in a test class as an array of bytes or whatever.
Author
Owner

@StefH commented on GitHub (Apr 10, 2020):

I've already build a test like this:

[Theory]
        [InlineData("gzip")]
        [InlineData("deflate")]
        public async Task WireMockServer_Should_SupportRequestGZipAndDeflate(string contentEncoding)
        {
            // Arrange
            const string body = "hello wiremock";
            byte[] compressed = CompressionUtils.Compress(contentEncoding, Encoding.UTF8.GetBytes(body));

            var server = WireMockServer.Start();
            server.Given(
                Request.Create()
                    .WithPath("/foo")
                    .WithBody("hello wiremock")
            )
            .RespondWith(
                Response.Create().WithBody("OK")
            );

            var content = new StreamContent(new MemoryStream(compressed));
            content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");
            content.Headers.ContentEncoding.Add(contentEncoding);

            // Act
            var response = await new HttpClient().PostAsync($"{server.Urls[0]}/foo", content);

            // Assert
            Check.That(await response.Content.ReadAsStringAsync()).Contains("OK");
        }

So I think we are good to go.

I will merge the PR and create a new Docker image this weekend and close this PR.

Just test it when you have time, and if you still find an problem, just create an issue.

@StefH commented on GitHub (Apr 10, 2020): I've already build a test like this: ``` c# [Theory] [InlineData("gzip")] [InlineData("deflate")] public async Task WireMockServer_Should_SupportRequestGZipAndDeflate(string contentEncoding) { // Arrange const string body = "hello wiremock"; byte[] compressed = CompressionUtils.Compress(contentEncoding, Encoding.UTF8.GetBytes(body)); var server = WireMockServer.Start(); server.Given( Request.Create() .WithPath("/foo") .WithBody("hello wiremock") ) .RespondWith( Response.Create().WithBody("OK") ); var content = new StreamContent(new MemoryStream(compressed)); content.Headers.ContentType = new MediaTypeHeaderValue("text/plain"); content.Headers.ContentEncoding.Add(contentEncoding); // Act var response = await new HttpClient().PostAsync($"{server.Urls[0]}/foo", content); // Assert Check.That(await response.Content.ReadAsStringAsync()).Contains("OK"); } ``` So I think we are good to go. I will merge the PR and create a new Docker image this weekend and close this PR. Just test it when you have time, and if you still find an problem, just create an issue.
Author
Owner

@StefH commented on GitHub (Apr 10, 2020):

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

@StefH commented on GitHub (Apr 10, 2020): https://github.com/WireMock-Net/WireMock.Net/pull/439
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#252