mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
proxy: add Host header checking
fix issue #993 Signed-off-by: Tw <tw19881113@gmail.com>
This commit is contained in:
parent
c110b27ef5
commit
94c63e42d6
1 changed files with 9 additions and 0 deletions
|
@ -357,9 +357,11 @@ func TestUpstreamHeadersUpdate(t *testing.T) {
|
|||
defer log.SetOutput(os.Stderr)
|
||||
|
||||
var actualHeaders http.Header
|
||||
var actualHost string
|
||||
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("Hello, client"))
|
||||
actualHeaders = r.Header
|
||||
actualHost = r.Host
|
||||
}))
|
||||
defer backend.Close()
|
||||
|
||||
|
@ -371,6 +373,7 @@ func TestUpstreamHeadersUpdate(t *testing.T) {
|
|||
"+Add-Me": {"Add-Value"},
|
||||
"-Remove-Me": {""},
|
||||
"Replace-Me": {"{hostname}"},
|
||||
"Host": {"{>Host}"},
|
||||
}
|
||||
// set up proxy
|
||||
p := &Proxy{
|
||||
|
@ -385,10 +388,12 @@ func TestUpstreamHeadersUpdate(t *testing.T) {
|
|||
}
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
const expectHost = "example.com"
|
||||
//add initial headers
|
||||
r.Header.Add("Merge-Me", "Initial")
|
||||
r.Header.Add("Remove-Me", "Remove-Value")
|
||||
r.Header.Add("Replace-Me", "Replace-Value")
|
||||
r.Header.Add("Host", expectHost)
|
||||
|
||||
p.ServeHTTP(w, r)
|
||||
|
||||
|
@ -421,6 +426,10 @@ func TestUpstreamHeadersUpdate(t *testing.T) {
|
|||
t.Errorf("Request sent to upstream backend should replace value of %v header with %v. Instead value was %v", headerKey, headerValue, value)
|
||||
}
|
||||
|
||||
if actualHost != expectHost {
|
||||
t.Errorf("Request sent to upstream backend should have value of Host with %s, but got %s", expectHost, actualHost)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestDownstreamHeadersUpdate(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue