Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hoverfly replaces "Host" header in SPY mode #1013

Open
ghazi94 opened this issue Apr 3, 2022 · 1 comment
Open

Hoverfly replaces "Host" header in SPY mode #1013

ghazi94 opened this issue Apr 3, 2022 · 1 comment

Comments

@ghazi94
Copy link

ghazi94 commented Apr 3, 2022

Description of the bug

I am using hoverfly-java (0.14.0) with my Spring project in integration testing.
My actual service (under test/spy) calls are routed through envoy which relies on the Host: X header - where X specifies the service name.
For example, this is the original request:

{
    "method" : "GET",
    "url" : "http://localhost:9211/sample-path/1",
    "queryStringParameters" : {},
    "headers" : {
      "Host" : [ "my-service.service" ],
      "Accept" : [ "application/json" ]
    }
  }

While using Hoverfly in SPY mode, it is proxying requests but replacing the Host header to finally have this request:

{
    "method" : "GET",
    "url" : "http://localhost:{hoverlfy-port}/sample-path/1",
    "queryStringParameters" : {},
    "headers" : {
      "Host" : [ "localhost:9211" ],
      "Accept" : [ "application/json" ]
    }
  }

This makes the underlying service unable to route requests.

Is it possible to specify custom header for Hoverfly to use internally for forwarding requests? Or can I explicitly re-set the header using a hack?

Steps to reproduce the issue

I can upload a sample project in the discussion below - however, the issue is easy to reproduce with SPY mode.

Observed result

404 Not Found due to wrong Host header

Expected result

200 OK

@tommysitu tommysitu transferred this issue from SpectoLabs/hoverfly-java May 21, 2022
@tommysitu
Copy link
Member

I went through some debugging and couldn't see anywhere in goproxy or hoverfly that would remove the Host header, and then I found this in the golang HTTP doc:

// For incoming requests, the Host header is promoted to the
// Request.Host field and removed from the Header map.

It's surprising to see that's how the go HTTP package behaves. As hoverfly doesn't see the original Host header, it cannot reconstruct the original request with the Host header value you supply.

You can read more about the original Go issue on Github: golang/go#7682

A workaround is probably to use a custom host header for routing, however I'm not sure if your envoy proxy supports it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants