directRequest modifies only req.URL so that it points to the upstream in the given DialInfo. It must modify ONLY the request URL.
(req *http.Request, di DialInfo)
| 1400 | // directRequest modifies only req.URL so that it points to the upstream |
| 1401 | // in the given DialInfo. It must modify ONLY the request URL. |
| 1402 | func (h *Handler) directRequest(req *http.Request, di DialInfo) { |
| 1403 | // we need a host, so set the upstream's host address |
| 1404 | reqHost := di.Address |
| 1405 | |
| 1406 | // if the port equates to the scheme, strip the port because |
| 1407 | // it's weird to make a request like http://example.com:80/. |
| 1408 | if (req.URL.Scheme == "http" && di.Port == "80") || |
| 1409 | (req.URL.Scheme == "https" && di.Port == "443") { |
| 1410 | reqHost = di.Host |
| 1411 | } |
| 1412 | |
| 1413 | // add client address to the host to let transport differentiate requests from different clients |
| 1414 | if ppt, ok := h.Transport.(ProxyProtocolTransport); ok && ppt.ProxyProtocolEnabled() { |
| 1415 | if proxyProtocolInfo, ok := caddyhttp.GetVar(req.Context(), proxyProtocolInfoVarKey).(ProxyProtocolInfo); ok { |
| 1416 | // encode the request so it plays well with h2 transport, it's unnecessary for h1 but anyway |
| 1417 | // The issue is that h2 transport will use the address to determine if new connections are needed |
| 1418 | // to roundtrip requests but the without escaping, new connections are constantly created and closed until |
| 1419 | // file descriptors are exhausted. |
| 1420 | // see: https://github.com/caddyserver/caddy/issues/7529 |
| 1421 | reqHost = url.QueryEscape(proxyProtocolInfo.AddrPort.String() + "->" + reqHost) |
| 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | req.URL.Host = reqHost |
| 1426 | } |
| 1427 | |
| 1428 | func (h Handler) provisionUpstream(upstream *Upstream, dynamic bool) { |
| 1429 | // create or get the host representation for this upstream; |
no test coverage detected