Question: proxy passthrough when no match? #151

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

Originally created by @ArtemTrofimushkin on GitHub (Nov 7, 2018).

Hi everyone.
I am using this library for my integration tests and have some issues with it.
Let me explain my setup and scenario.
Setup:

  • Backend service, working on full .NET Framework 4.6.2 (legacy application).
  • Frontend service, working on .NET Core 2.1.

Scenario: Cover frontend service with integration tests.
Implementation:
Integration tests, frontend and library (WireMock.Net-docker) running in a docker. I want the following: setup proxy to backend for all endpoints by default, except that I want to mock with special json stub and try to test logic in my fontend service.
For configuration of mocking/proxy I've created simple utility lib, that uses Admin REST API of WireMock.NET library. But, configured proxy doesn't response for any requests when I run tests. When I tried to figure out what happened with the proxy, I cloned repository and ran it locally.
After some debugging and researching already closed issues, I saw the following lines of the code (OwinResponseMapper.MapAsync):

#if !USE_ASPNETCORE // For non-NETSTANDARD, check if this response header can be added (#148)
    if (!WebHeaderCollection.IsRestricted(pair.Key, true))
    {
        response.Headers.AppendValues(pair.Key, pair.Value.ToArray());
    }
#else
    // NETSTANDARD can add any header (or so it seems)
    response.Headers.Append(pair.Key, pair.Value.ToArray());
#endif

When I tried to change the target of the solution to the .NET Core 2.1 only and convert code to following:

if (!WebHeaderCollection.IsRestricted(pair.Key, true))
{
    response.Headers.Append(pair.Key, pair.Value.ToArray());
}

It started to work as I expected. Something similar was in already closed issue (https://github.com/WireMock-Net/WireMock.Net/issues/148).
After some researching, I found that my backend server was responding with following HTTP header: Transfer-Encoding chunked. This header was excluded by this method: WebHeaderCollection.IsRestricted in .NET Core 2.1. It seems that this library needs some fixes for such HTTP headers.

Originally created by @ArtemTrofimushkin on GitHub (Nov 7, 2018). Hi everyone. I am using this library for my integration tests and have some issues with it. Let me explain my setup and scenario. Setup: * Backend service, working on full .NET Framework 4.6.2 (legacy application). * Frontend service, working on .NET Core 2.1. Scenario: Cover frontend service with integration tests. Implementation: Integration tests, frontend and library (WireMock.Net-docker) running in a docker. I want the following: setup proxy to backend for all endpoints by default, except that I want to mock with special json stub and try to test logic in my fontend service. For configuration of mocking/proxy I've created simple utility lib, that uses Admin REST API of WireMock.NET library. But, configured proxy doesn't response for any requests when I run tests. When I tried to figure out what happened with the proxy, I cloned repository and ran it locally. After some debugging and researching already closed issues, I saw the following lines of the code (OwinResponseMapper.MapAsync): ``` c# #if !USE_ASPNETCORE // For non-NETSTANDARD, check if this response header can be added (#148) if (!WebHeaderCollection.IsRestricted(pair.Key, true)) { response.Headers.AppendValues(pair.Key, pair.Value.ToArray()); } #else // NETSTANDARD can add any header (or so it seems) response.Headers.Append(pair.Key, pair.Value.ToArray()); #endif ``` When I tried to change the target of the solution to the .NET Core 2.1 only and convert code to following: ``` c# if (!WebHeaderCollection.IsRestricted(pair.Key, true)) { response.Headers.Append(pair.Key, pair.Value.ToArray()); } ``` It started to work as I expected. Something similar was in already closed issue (https://github.com/WireMock-Net/WireMock.Net/issues/148). After some researching, I found that my backend server was responding with following HTTP header: *Transfer-Encoding chunked*. This header was excluded by this method: WebHeaderCollection.IsRestricted in .NET Core 2.1. It seems that this library needs some fixes for such HTTP headers.
adam added the question label 2025-12-29 08:22:59 +01:00
adam closed this issue 2025-12-29 08:22:59 +01:00
Author
Owner

@s-krawczyk commented on GitHub (Nov 7, 2018):

Got same issue moment ago. Funny ;) What I can do on my side. How to "hack" this?

@s-krawczyk commented on GitHub (Nov 7, 2018): Got same issue moment ago. Funny ;) What I can do on my side. How to "hack" this?
Author
Owner

@StefH commented on GitHub (Nov 7, 2018):

I've modified the code so that I manually check all restricted response headers as defined here:
https://docs.microsoft.com/en-us/dotnet/api/system.net.webheadercollection.isrestricted?view=netframework-4.7.2

    Accept

    Connection

    Content-Length

    Content-Type

    Date

    Expect

    Host

    If-Modified-Since

    Range

    Referer

    Transfer-Encoding

    User-Agent

    Proxy-Connection

See the branch:
https://github.com/WireMock-Net/WireMock.Net/tree/restricted_headers

Can you test if this works for both net4x and netstandard 2.0 / netcore app 2,1 ?

@StefH commented on GitHub (Nov 7, 2018): I've modified the code so that I manually check all restricted response headers as defined here: https://docs.microsoft.com/en-us/dotnet/api/system.net.webheadercollection.isrestricted?view=netframework-4.7.2 ``` Accept Connection Content-Length Content-Type Date Expect Host If-Modified-Since Range Referer Transfer-Encoding User-Agent Proxy-Connection ``` See the branch: https://github.com/WireMock-Net/WireMock.Net/tree/restricted_headers Can you test if this works for both net4x and netstandard 2.0 / netcore app 2,1 ?
Author
Owner

@StefH commented on GitHub (Nov 7, 2018):

Or you can test version 1.0.4.19-ci-1475 from MyGet

@StefH commented on GitHub (Nov 7, 2018): Or you can test version `1.0.4.19-ci-1475` from MyGet
Author
Owner

@ArtemTrofimushkin commented on GitHub (Nov 7, 2018):

Yep, this version works for my .NET Core 2.1 project

@ArtemTrofimushkin commented on GitHub (Nov 7, 2018): Yep, this version works for my .NET Core 2.1 project
Author
Owner

@StefH commented on GitHub (Nov 7, 2018):

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

@StefH commented on GitHub (Nov 7, 2018): https://github.com/WireMock-Net/WireMock.Net/pull/228
Author
Owner

@StefH commented on GitHub (Nov 7, 2018):

Closing

@StefH commented on GitHub (Nov 7, 2018): Closing
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#151