MCPcopy Create free account
hub / github.com/zalando/skipper / TestHostHeader

Function TestHostHeader

proxy/proxy_test.go:1341–1508  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1339}
1340
1341func TestHostHeader(t *testing.T) {
1342 // start a test backend that returns the received host header
1343 backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1344 w.Header().Set("X-Received-Host", r.Host)
1345 }))
1346 defer backend.Close()
1347
1348 // take the generated host part of the backend
1349 bu, err := url.Parse(backend.URL)
1350 if err != nil {
1351 t.Error("failed to parse test backend url")
1352 return
1353 }
1354 backendHost := bu.Host
1355
1356 for _, ti := range []struct {
1357 msg string
1358 flags Flags
1359 routeFmt string
1360 incomingHost string
1361 expectedHost string
1362 }{{
1363 "no proxy preserve",
1364 FlagsNone,
1365 `route: Any() -> "%s"`,
1366 "www.example.org",
1367 backendHost,
1368 }, {
1369 "no proxy preserve, route preserve not",
1370 FlagsNone,
1371 `route: Any() -> preserveHost("false") -> "%s"`,
1372 "www.example.org",
1373 backendHost,
1374 }, {
1375 "no proxy preserve, route preserve",
1376 FlagsNone,
1377 `route: Any() -> preserveHost("true") -> "%s"`,
1378 "www.example.org",
1379 "www.example.org",
1380 }, {
1381 "no proxy preserve, route preserve not, explicit host last",
1382 FlagsNone,
1383 `route: Any() -> preserveHost("false") -> setRequestHeader("Host", "custom.example.org") -> "%s"`,
1384 "www.example.org",
1385 "custom.example.org",
1386 }, {
1387 "no proxy preserve, route preserve, explicit host last",
1388 FlagsNone,
1389 `route: Any() -> preserveHost("true") -> setRequestHeader("Host", "custom.example.org") -> "%s"`,
1390 "www.example.org",
1391 "custom.example.org",
1392 }, {
1393 "no proxy preserve, route preserve not, explicit host first",
1394 FlagsNone,
1395 `route: Any() -> setRequestHeader("Host", "custom.example.org") -> preserveHost("false") -> "%s"`,
1396 "www.example.org",
1397 "custom.example.org",
1398 }, {

Callers

nothing calls this directly

Calls 11

newTestProxyFunction · 0.85
closeAllFunction · 0.85
SetMethod · 0.65
CloseMethod · 0.65
ParseMethod · 0.65
ErrorMethod · 0.65
DoMethod · 0.65
DebugMethod · 0.65
GetMethod · 0.65
HeaderMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…