mock-server / mockserver

MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby. MockServer also includes a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding).
http://mock-server.com
Apache License 2.0
4.57k stars 1.07k forks source link

Problems with html pages using httpForward #271

Closed xenaCode closed 7 years ago

xenaCode commented 8 years ago

Hi James, I'm not sure if writing an issue is the right approach for asking this question. I have the next configuration:

mockServerClient("localhost", 8888).mockAnyResponse(
    {
        'httpRequest': {
            'method': 'GET',
        },
        "httpForward": {
            "host": "",
            "port": 8887,
            "scheme": "HTTP"
        },
        'times': {
            'unlimited': true
        }
    }
);

Then I run server: java -jar mockserver-netty-3.10.4-jar-with-dependencies.jar -serverPort 8888 and run SimpleHTTPServer on port 8887. It works good but when requested html pages, MockServer added Content-Type: text/plain, although in response its value is text/html. In Wireshark I got:

Src port: 8887
Status Code: 200
Response Phrase: OK
Content-Type: text/html 
etc.

Src port: 8888
Status Code: 200
Response Phrase: OK
Content-Type: text/html 
Content-Type: text/plain 
etc.

And it's displayed as plain text and not as html. It's obviously that MockServer added the second Content-Type to response. But why it's happend? I tried to change configuration in different way, but it's still not working.

Hope I am able to explain the scenario that I am struggling with. Any help would be really appreciated.

Thanks a lot, Xena

vojtoshik commented 8 years ago

I faced exactly the same problem today, but in my case, it adds Content-Type: text/plain if it's not set, which changes the logic of processing in downstream application

jamesdbloom commented 7 years ago

I believe this should now be resolved, but as I couldn't manage to reduce the duplicate Content-Type header issue I can't be sure its 100% fixed. This fix will be in a new release in the next week or so.