/* Copyright 2014 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package proxy import ( "bytes" "compress/flate" "compress/gzip" "fmt" "io/ioutil" "net/http" "net/http/httptest" "net/url" "strings" "testing" ) func parseURLOrDie(inURL string) *url.URL { parsed, err := url.Parse(inURL) if err != nil { panic(err) } return parsed } func TestProxyTransport(t *testing.T) { testTransport := &Transport{ Scheme: "http", Host: "foo.com", PathPrepend: "/proxy/node/node1:10250", } testTransport2 := &Transport{ Scheme: "https", Host: "foo.com", PathPrepend: "/proxy/node/node1:8080", } emptyHostTransport := &Transport{ Scheme: "https", PathPrepend: "/proxy/node/node1:10250", } emptySchemeTransport := &Transport{ Host: "foo.com", PathPrepend: "/proxy/node/node1:10250", } emptyHostAndSchemeTransport := &Transport{ PathPrepend: "/proxy/node/node1:10250", } type Item struct { input string sourceURL string transport *Transport output string contentType string forwardedURI string redirect string redirectWant string reqHost string } table := map[string]Item{ "normal": { input: `
kubelet.loggoogle.log
`, sourceURL: "http://mynode.com/logs/log.log", transport: testTransport, output: `
kubelet.loggoogle.log
`, contentType: "text/html", forwardedURI: "/proxy/node/node1:10250/logs/log.log", }, "full document": { input: `
kubelet.loggoogle.log
`, sourceURL: "http://mynode.com/logs/log.log", transport: testTransport, output: `
kubelet.loggoogle.log
`, contentType: "text/html", forwardedURI: "/proxy/node/node1:10250/logs/log.log", }, "trailing slash": { input: `
kubelet.loggoogle.log
`, sourceURL: "http://mynode.com/logs/log.log", transport: testTransport, output: `
kubelet.loggoogle.log
`, contentType: "text/html", forwardedURI: "/proxy/node/node1:10250/logs/log.log", }, "content-type charset": { input: `
kubelet.loggoogle.log
`, sourceURL: "http://mynode.com/logs/log.log", transport: testTransport, output: `
kubelet.loggoogle.log
`, contentType: "text/html; charset=utf-8", forwardedURI: "/proxy/node/node1:10250/logs/log.log", }, "content-type passthrough": { input: `
kubelet.loggoogle.log
`, sourceURL: "http://mynode.com/logs/log.log", transport: testTransport, output: `
kubelet.loggoogle.log
`, contentType: "text/plain", forwardedURI: "/proxy/node/node1:10250/logs/log.log", }, "subdir": { input: `kubelet.loggoogle.log`, sourceURL: "http://mynode.com/whatever/apt/somelog.log", transport: testTransport2, output: `kubelet.loggoogle.log`, contentType: "text/html", forwardedURI: "/proxy/node/node1:8080/whatever/apt/somelog.log", }, "image": { input: `
`, sourceURL: "http://mynode.com/", transport: testTransport, output: `
`, contentType: "text/html", forwardedURI: "/proxy/node/node1:10250/", }, "abs": { input: `