Merge pull request #492 from ibigbug/support-x-forwarded-host

Add X-Forwarded-Host for http proxy
pull/561/head
Silver 10 months ago committed by GitHub
commit 10fc450ae5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      ingress/origin_proxy.go
  2. 9
      ingress/origin_proxy_test.go

@ -40,6 +40,8 @@ func (o *httpService) RoundTrip(req *http.Request) (*http.Response, error) {
if o.hostHeader != "" {
// For incoming requests, the Host header is promoted to the Request.Host field and removed from the Header map.
// Pass the original Host header as X-Forwarded-Host.
req.Header.Set("X-Forwarded-Host", req.Host)
req.Host = o.hostHeader
}
return o.transport.RoundTrip(req)

@ -3,6 +3,7 @@ package ingress
import (
"context"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/http/httptest"
@ -118,7 +119,9 @@ func TestHTTPServiceHostHeaderOverride(t *testing.T) {
w.WriteHeader(http.StatusSwitchingProtocols)
return
}
w.Write([]byte("ok"))
// return the X-Forwarded-Host header for assertions
// as the httptest Server URL isn't available here yet
w.Write([]byte(r.Header.Get("X-Forwarded-Host")))
}
origin := httptest.NewServer(http.HandlerFunc(handler))
defer origin.Close()
@ -141,6 +144,10 @@ func TestHTTPServiceHostHeaderOverride(t *testing.T) {
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
respBody, err := ioutil.ReadAll(resp.Body)
require.NoError(t, err)
require.Equal(t, respBody, []byte(originURL.Host))
}
func tcpListenRoutine(listener net.Listener, closeChan chan struct{}) {

Loading…
Cancel
Save