mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 12:07:47 +00:00
Merge pull request #15784 from csrwng/remove_blank_proxy_headers
Auto commit by PR queue bot
This commit is contained in:
commit
746aae4c17
@ -86,8 +86,12 @@ func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
|||||||
forwardedURI = forwardedURI + "/"
|
forwardedURI = forwardedURI + "/"
|
||||||
}
|
}
|
||||||
req.Header.Set("X-Forwarded-Uri", forwardedURI)
|
req.Header.Set("X-Forwarded-Uri", forwardedURI)
|
||||||
|
if len(t.Host) > 0 {
|
||||||
req.Header.Set("X-Forwarded-Host", t.Host)
|
req.Header.Set("X-Forwarded-Host", t.Host)
|
||||||
|
}
|
||||||
|
if len(t.Scheme) > 0 {
|
||||||
req.Header.Set("X-Forwarded-Proto", t.Scheme)
|
req.Header.Set("X-Forwarded-Proto", t.Scheme)
|
||||||
|
}
|
||||||
|
|
||||||
rt := t.RoundTripper
|
rt := t.RoundTripper
|
||||||
if rt == nil {
|
if rt == nil {
|
||||||
|
@ -45,6 +45,14 @@ func TestProxyTransport(t *testing.T) {
|
|||||||
Host: "foo.com",
|
Host: "foo.com",
|
||||||
PathPrepend: "/proxy/minion/minion1:8080",
|
PathPrepend: "/proxy/minion/minion1:8080",
|
||||||
}
|
}
|
||||||
|
emptyHostTransport := &Transport{
|
||||||
|
Scheme: "https",
|
||||||
|
PathPrepend: "/proxy/minion/minion1:10250",
|
||||||
|
}
|
||||||
|
emptySchemeTransport := &Transport{
|
||||||
|
Host: "foo.com",
|
||||||
|
PathPrepend: "/proxy/minion/minion1:10250",
|
||||||
|
}
|
||||||
type Item struct {
|
type Item struct {
|
||||||
input string
|
input string
|
||||||
sourceURL string
|
sourceURL string
|
||||||
@ -158,6 +166,22 @@ func TestProxyTransport(t *testing.T) {
|
|||||||
contentType: "text/html",
|
contentType: "text/html",
|
||||||
forwardedURI: "/proxy/minion/minion1:10250/logs/log.log",
|
forwardedURI: "/proxy/minion/minion1:10250/logs/log.log",
|
||||||
},
|
},
|
||||||
|
"no host": {
|
||||||
|
input: "<html></html>",
|
||||||
|
sourceURL: "http://myminion.com/logs/log.log",
|
||||||
|
transport: emptyHostTransport,
|
||||||
|
output: "<html></html>",
|
||||||
|
contentType: "text/html",
|
||||||
|
forwardedURI: "/proxy/minion/minion1:10250/logs/log.log",
|
||||||
|
},
|
||||||
|
"no scheme": {
|
||||||
|
input: "<html></html>",
|
||||||
|
sourceURL: "http://myminion.com/logs/log.log",
|
||||||
|
transport: emptySchemeTransport,
|
||||||
|
output: "<html></html>",
|
||||||
|
contentType: "text/html",
|
||||||
|
forwardedURI: "/proxy/minion/minion1:10250/logs/log.log",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
testItem := func(name string, item *Item) {
|
testItem := func(name string, item *Item) {
|
||||||
@ -166,12 +190,26 @@ func TestProxyTransport(t *testing.T) {
|
|||||||
if got, want := r.Header.Get("X-Forwarded-Uri"), item.forwardedURI; got != want {
|
if got, want := r.Header.Get("X-Forwarded-Uri"), item.forwardedURI; got != want {
|
||||||
t.Errorf("%v: X-Forwarded-Uri = %q, want %q", name, got, want)
|
t.Errorf("%v: X-Forwarded-Uri = %q, want %q", name, got, want)
|
||||||
}
|
}
|
||||||
|
if len(item.transport.Host) == 0 {
|
||||||
|
_, present := r.Header["X-Forwarded-Host"]
|
||||||
|
if present {
|
||||||
|
t.Errorf("%v: X-Forwarded-Host header should not be present", name)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if got, want := r.Header.Get("X-Forwarded-Host"), item.transport.Host; got != want {
|
if got, want := r.Header.Get("X-Forwarded-Host"), item.transport.Host; got != want {
|
||||||
t.Errorf("%v: X-Forwarded-Host = %q, want %q", name, got, want)
|
t.Errorf("%v: X-Forwarded-Host = %q, want %q", name, got, want)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if len(item.transport.Scheme) == 0 {
|
||||||
|
_, present := r.Header["X-Forwarded-Proto"]
|
||||||
|
if present {
|
||||||
|
t.Errorf("%v: X-Forwarded-Proto header should not be present", name)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if got, want := r.Header.Get("X-Forwarded-Proto"), item.transport.Scheme; got != want {
|
if got, want := r.Header.Get("X-Forwarded-Proto"), item.transport.Scheme; got != want {
|
||||||
t.Errorf("%v: X-Forwarded-Proto = %q, want %q", name, got, want)
|
t.Errorf("%v: X-Forwarded-Proto = %q, want %q", name, got, want)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Send response.
|
// Send response.
|
||||||
if item.redirect != "" {
|
if item.redirect != "" {
|
||||||
|
Loading…
Reference in New Issue
Block a user