| 1 | // Copyright 2015 Matthew Holt and The Caddy Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package reverseproxyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ |
| 16 | |
| 17 | import ( |
| 18 | "contextscip-go gomod github.com/golang/go/src go1.25.1 context/" |
| 19 | "crypto/tlsscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/" |
| 20 | "crypto/x509scip-go gomod github.com/golang/go/src go1.25.1 `crypto/x509`/" |
| 21 | "encoding/base64scip-go gomod github.com/golang/go/src go1.25.1 `encoding/base64`/" |
| 22 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/" |
| 23 | "fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/" |
| 24 | weakrandscip-go gomod github.com/golang/go/src go1.25.1 `math/rand/v2`/ "math/rand/v2scip-go gomod github.com/golang/go/src go1.25.1 `math/rand/v2`/" |
| 25 | "netscip-go gomod github.com/golang/go/src go1.25.1 net/" |
| 26 | "net/httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/" |
| 27 | "net/urlscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/" |
| 28 | "osscip-go gomod github.com/golang/go/src go1.25.1 os/" |
| 29 | "reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/" |
| 30 | "slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/" |
| 31 | "stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/" |
| 32 | "timescip-go gomod github.com/golang/go/src go1.25.1 time/" |
| 33 | |
| 34 | "github.com/pires/go-proxyprotoscip-go gomod github.com/pires/go-proxyproto v0.12.0 `github.com/pires/go-proxyproto`/" |
| 35 | "github.com/quic-go/quic-go/http3scip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/" |
| 36 | "go.uber.org/zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/" |
| 37 | "go.uber.org/zap/zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/" |
| 38 | "golang.org/x/net/http2scip-go gomod golang.org/x/net v0.55.0 `golang.org/x/net/http2`/" |
| 39 | |
| 40 | "github.com/caddyserver/caddy/v2scip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/" |
| 41 | "github.com/caddyserver/caddy/v2/caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/" |
| 42 | "github.com/caddyserver/caddy/v2/modules/caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/" |
| 43 | "github.com/caddyserver/caddy/v2/modules/caddyhttp/headersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/headers`/" |
| 44 | "github.com/caddyserver/caddy/v2/modules/caddytlsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/" |
| 45 | "github.com/caddyserver/caddy/v2/modules/internal/networkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/internal/network`/" |
| 46 | ) |
| 47 | |
| 48 | func initscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/init().() { |
| 49 | caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.RegisterModulescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/RegisterModule().(HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#{}) |
| 50 | } |
| 51 | |
| 52 | // HTTPTransport is essentially a configuration wrapper for http.Transport. |
| 53 | // It defines a JSON structure useful when configuring the HTTP transport |
| 54 | // for Caddy's reverse proxy. It builds its http.Transport at Provision. |
| 55 | type HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport# struct { |
| 56 | // TODO: It's possible that other transports (like fastcgi) might be |
| 57 | // able to borrow/use at least some of these config fields; if so, |
| 58 | // maybe move them into a type called CommonTransport and embed it? |
| 59 | |
| 60 | // Configures the DNS resolver used to resolve the IP address of upstream hostnames. |
| 61 | Resolverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Resolver. *UpstreamResolverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/UpstreamResolver# `json:"resolver,omitempty"` |
| 62 | |
| 63 | // Configures TLS to the upstream. Setting this to an empty struct |
| 64 | // is sufficient to enable TLS with reasonable defaults. |
| 65 | TLSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#TLS. *TLSConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig# `json:"tls,omitempty"` |
| 66 | |
| 67 | // Configures HTTP Keep-Alive (enabled by default). Should only be |
| 68 | // necessary if rigorous testing has shown that tuning this helps |
| 69 | // improve performance. |
| 70 | KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#KeepAlive. *KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive# `json:"keep_alive,omitempty"` |
| 71 | |
| 72 | // Whether to enable compression to upstream. Default: true |
| 73 | Compressionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Compression. *bool `json:"compression,omitempty"` |
| 74 | |
| 75 | // Maximum number of connections per host. Default: 0 (no limit) |
| 76 | MaxConnsPerHostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#MaxConnsPerHost. int `json:"max_conns_per_host,omitempty"` |
| 77 | |
| 78 | // If non-empty, which PROXY protocol version to send when |
| 79 | // connecting to an upstream. Default: off. |
| 80 | ProxyProtocolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#ProxyProtocol. string `json:"proxy_protocol,omitempty"` |
| 81 | |
| 82 | // URL to the server that the HTTP transport will use to proxy |
| 83 | // requests to the upstream. See http.Transport.Proxy for |
| 84 | // information regarding supported protocols. This value takes |
| 85 | // precedence over `HTTP_PROXY`, etc. |
| 86 | // |
| 87 | // Providing a value to this parameter results in |
| 88 | // requests flowing through the reverse_proxy in the following |
| 89 | // way: |
| 90 | // |
| 91 | // User Agent -> |
| 92 | // reverse_proxy -> |
| 93 | // forward_proxy_url -> upstream |
| 94 | // |
| 95 | // Default: http.ProxyFromEnvironment |
| 96 | // DEPRECATED: Use NetworkProxyRaw|`network_proxy` instead. Subject to removal. |
| 97 | ForwardProxyURLscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#ForwardProxyURL. string `json:"forward_proxy_url,omitempty"` |
| 98 | |
| 99 | // How long to wait before timing out trying to connect to |
| 100 | // an upstream. Default: `3s`. |
| 101 | DialTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#DialTimeout. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Durationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Duration# `json:"dial_timeout,omitempty"` |
| 102 | |
| 103 | // How long to wait before spawning an RFC 6555 Fast Fallback |
| 104 | // connection. A negative value disables this. Default: `300ms`. |
| 105 | FallbackDelayscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#FallbackDelay. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Durationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Duration# `json:"dial_fallback_delay,omitempty"` |
| 106 | |
| 107 | // How long to wait for reading response headers from server. Default: No timeout. |
| 108 | ResponseHeaderTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#ResponseHeaderTimeout. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Durationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Duration# `json:"response_header_timeout,omitempty"` |
| 109 | |
| 110 | // The length of time to wait for a server's first response |
| 111 | // headers after fully writing the request headers if the |
| 112 | // request has a header "Expect: 100-continue". Default: No timeout. |
| 113 | ExpectContinueTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#ExpectContinueTimeout. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Durationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Duration# `json:"expect_continue_timeout,omitempty"` |
| 114 | |
| 115 | // The maximum bytes to read from response headers. Default: `10MiB`. |
| 116 | MaxResponseHeaderSizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#MaxResponseHeaderSize. int64 `json:"max_response_header_size,omitempty"` |
| 117 | |
| 118 | // The size of the write buffer in bytes. Default: `4KiB`. |
| 119 | WriteBufferSizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#WriteBufferSize. int `json:"write_buffer_size,omitempty"` |
| 120 | |
| 121 | // The size of the read buffer in bytes. Default: `4KiB`. |
| 122 | ReadBufferSizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#ReadBufferSize. int `json:"read_buffer_size,omitempty"` |
| 123 | |
| 124 | // The maximum time to wait for next read from backend. Default: no timeout. |
| 125 | ReadTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#ReadTimeout. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Durationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Duration# `json:"read_timeout,omitempty"` |
| 126 | |
| 127 | // The maximum time to wait for next write to backend. Default: no timeout. |
| 128 | WriteTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#WriteTimeout. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Durationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Duration# `json:"write_timeout,omitempty"` |
| 129 | |
| 130 | // The versions of HTTP to support. As a special case, "h2c" |
| 131 | // can be specified to use H2C (HTTP/2 over Cleartext) to the |
| 132 | // upstream (this feature is experimental and subject to |
| 133 | // change or removal). Default: ["1.1", "2"] |
| 134 | // |
| 135 | // EXPERIMENTAL: "3" enables HTTP/3, but it must be the only |
| 136 | // version specified if enabled. Additionally, HTTPS must be |
| 137 | // enabled to the upstream as HTTP/3 requires TLS. Subject |
| 138 | // to change or removal while experimental. |
| 139 | Versionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Versions. []string `json:"versions,omitempty"` |
| 140 | |
| 141 | // Specify the address to bind to when connecting to an upstream. In other words, |
| 142 | // it is the address the upstream sees as the remote address. |
| 143 | LocalAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#LocalAddress. string `json:"local_address,omitempty"` |
| 144 | |
| 145 | // The pre-configured underlying HTTP transport. |
| 146 | Transportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Transport. *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Transportscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport# `json:"-"` |
| 147 | |
| 148 | // The module that provides the network (forward) proxy |
| 149 | // URL that the HTTP transport will use to proxy |
| 150 | // requests to the upstream. See [http.Transport.Proxy](https://pkg.go.dev/net/http#Transport.Proxy) |
| 151 | // for information regarding supported protocols. |
| 152 | // |
| 153 | // Providing a value to this parameter results in requests |
| 154 | // flowing through the reverse_proxy in the following way: |
| 155 | // |
| 156 | // User Agent -> |
| 157 | // reverse_proxy -> |
| 158 | // [proxy provided by the module] -> upstream |
| 159 | // |
| 160 | // If nil, defaults to reading the `HTTP_PROXY`, |
| 161 | // `HTTPS_PROXY`, and `NO_PROXY` environment variables. |
| 162 | NetworkProxyRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#NetworkProxyRaw. jsonscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/RawMessage# `json:"network_proxy,omitempty" caddy:"namespace=caddy.network_proxy inline_key=from"` |
| 163 | |
| 164 | h3Transportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#h3Transport. *http3scip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/.Transportscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/Transport# // TODO: EXPERIMENTAL (May 2024) |
| 165 | } |
| 166 | |
| 167 | // CaddyModule returns the Caddy module information. |
| 168 | func (HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#) CaddyModulescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#CaddyModule().() caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ModuleInfoscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleInfo# { |
| 169 | return caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ModuleInfoscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleInfo#{ |
| 170 | IDscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleInfo#ID.: "http.reverse_proxy.transport.http", |
| 171 | Newscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ModuleInfo#New.: func() caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Modulescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Module# { return new(HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#) }, |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | var ( |
| 176 | allowedVersionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/allowedVersions. = []string{"1.1", "2", "h2c", "3"} |
| 177 | allowedVersionsStringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/allowedVersionsString. = stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Joinscip-go gomod github.com/golang/go/src go1.25.1 strings/Join().(allowedVersionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/allowedVersions., ", ") |
| 178 | ) |
| 179 | |
| 180 | // Provision sets up h.Transport with a *http.Transport |
| 181 | // that is ready to use. |
| 182 | func (h *HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#) Provisionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Provision().(ctx caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#) error { |
| 183 | if len(h.Versionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Versions.) == 0 { |
| 184 | h.Versionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Versions. = []string{"1.1", "2"} |
| 185 | } |
| 186 | // some users may provide http versions not recognized by caddy, instead of trying to |
| 187 | // guess the version, we just error out and let the user fix their config |
| 188 | // see: https://github.com/caddyserver/caddy/issues/7111 |
| 189 | for _, v := range h.Versionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Versions. { |
| 190 | if !slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/.Containsscip-go gomod github.com/golang/go/src go1.25.1 slices/Contains().(allowedVersionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/allowedVersions., v) { |
| 191 | return fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("unsupported HTTP version: %s, supported version: %s", v, allowedVersionsStringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/allowedVersionsString.) |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | rt, err := h.NewTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#NewTransport().(ctx) |
| 196 | if err != nil { |
| 197 | return err |
| 198 | } |
| 199 | h.Transportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Transport. = rt |
| 200 | |
| 201 | return nil |
| 202 | } |
| 203 | |
| 204 | // NewTransport builds a standard-lib-compatible http.Transport value from h. |
| 205 | func (h *HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#) NewTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#NewTransport().(caddyCtx caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#) (*httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Transportscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#, error) { |
| 206 | // Set keep-alive defaults if it wasn't otherwise configured |
| 207 | if h.KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#KeepAlive. == nil { |
| 208 | h.KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#KeepAlive. = new(KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive#) |
| 209 | } |
| 210 | if h.KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#KeepAlive..ProbeIntervalscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive#ProbeInterval. == 0 { |
| 211 | h.KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#KeepAlive..ProbeIntervalscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive#ProbeInterval. = caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Durationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Duration#(30 * timescip-go gomod github.com/golang/go/src go1.25.1 time/.Secondscip-go gomod github.com/golang/go/src go1.25.1 time/Second.) |
| 212 | } |
| 213 | if h.KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#KeepAlive..IdleConnTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive#IdleConnTimeout. == 0 { |
| 214 | h.KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#KeepAlive..IdleConnTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive#IdleConnTimeout. = caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Durationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Duration#(2 * timescip-go gomod github.com/golang/go/src go1.25.1 time/.Minutescip-go gomod github.com/golang/go/src go1.25.1 time/Minute.) |
| 215 | } |
| 216 | if h.KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#KeepAlive..MaxIdleConnsPerHostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive#MaxIdleConnsPerHost. == 0 { |
| 217 | h.KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#KeepAlive..MaxIdleConnsPerHostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive#MaxIdleConnsPerHost. = 32 // seems about optimal, see #2805 |
| 218 | } |
| 219 | |
| 220 | // Set a relatively short default dial timeout. |
| 221 | // This is helpful to make load-balancer retries more speedy. |
| 222 | if h.DialTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#DialTimeout. == 0 { |
| 223 | h.DialTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#DialTimeout. = caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Durationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Duration#(3 * timescip-go gomod github.com/golang/go/src go1.25.1 time/.Secondscip-go gomod github.com/golang/go/src go1.25.1 time/Second.) |
| 224 | } |
| 225 | |
| 226 | dialer := &netscip-go gomod github.com/golang/go/src go1.25.1 net/.Dialerscip-go gomod github.com/golang/go/src go1.25.1 net/Dialer#{ |
| 227 | Timeoutscip-go gomod github.com/golang/go/src go1.25.1 net/Dialer#Timeout.: timescip-go gomod github.com/golang/go/src go1.25.1 time/.Durationscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#(h.DialTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#DialTimeout.), |
| 228 | FallbackDelayscip-go gomod github.com/golang/go/src go1.25.1 net/Dialer#FallbackDelay.: timescip-go gomod github.com/golang/go/src go1.25.1 time/.Durationscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#(h.FallbackDelayscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#FallbackDelay.), |
| 229 | } |
| 230 | |
| 231 | if h.LocalAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#LocalAddress. != "" { |
| 232 | netaddr, err := caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ParseNetworkAddressWithDefaultsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ParseNetworkAddressWithDefaults().(h.LocalAddressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#LocalAddress., "tcp", 0) |
| 233 | if err != nil { |
| 234 | return nil, err |
| 235 | } |
| 236 | if netaddr.PortRangeSizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#PortRangeSize().() > 1 { |
| 237 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("local_address must be a single address, not a port range") |
| 238 | } |
| 239 | switch netaddr.Networkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#Network. { |
| 240 | case "tcp", "tcp4", "tcp6": |
| 241 | dialer.LocalAddrscip-go gomod github.com/golang/go/src go1.25.1 net/Dialer#LocalAddr., err = netscip-go gomod github.com/golang/go/src go1.25.1 net/.ResolveTCPAddrscip-go gomod github.com/golang/go/src go1.25.1 net/ResolveTCPAddr().(netaddr.Networkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#Network., netaddr.JoinHostPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#JoinHostPort().(0)) |
| 242 | if err != nil { |
| 243 | return nil, err |
| 244 | } |
| 245 | case "unix", "unixgram", "unixpacket": |
| 246 | dialer.LocalAddrscip-go gomod github.com/golang/go/src go1.25.1 net/Dialer#LocalAddr., err = netscip-go gomod github.com/golang/go/src go1.25.1 net/.ResolveUnixAddrscip-go gomod github.com/golang/go/src go1.25.1 net/ResolveUnixAddr().(netaddr.Networkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#Network., netaddr.JoinHostPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#JoinHostPort().(0)) |
| 247 | if err != nil { |
| 248 | return nil, err |
| 249 | } |
| 250 | case "udp", "udp4", "udp6": |
| 251 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("local_address must be a TCP address, not a UDP address") |
| 252 | default: |
| 253 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("unsupported network") |
| 254 | } |
| 255 | } |
| 256 | if h.Resolverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Resolver. != nil { |
| 257 | err := h.Resolverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Resolver..ParseAddressesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/UpstreamResolver#ParseAddresses().() |
| 258 | if err != nil { |
| 259 | return nil, err |
| 260 | } |
| 261 | d := &netscip-go gomod github.com/golang/go/src go1.25.1 net/.Dialerscip-go gomod github.com/golang/go/src go1.25.1 net/Dialer#{ |
| 262 | Timeoutscip-go gomod github.com/golang/go/src go1.25.1 net/Dialer#Timeout.: timescip-go gomod github.com/golang/go/src go1.25.1 time/.Durationscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#(h.DialTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#DialTimeout.), |
| 263 | FallbackDelayscip-go gomod github.com/golang/go/src go1.25.1 net/Dialer#FallbackDelay.: timescip-go gomod github.com/golang/go/src go1.25.1 time/.Durationscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#(h.FallbackDelayscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#FallbackDelay.), |
| 264 | } |
| 265 | dialer.Resolverscip-go gomod github.com/golang/go/src go1.25.1 net/Dialer#Resolver. = &netscip-go gomod github.com/golang/go/src go1.25.1 net/.Resolverscip-go gomod github.com/golang/go/src go1.25.1 net/Resolver#{ |
| 266 | PreferGoscip-go gomod github.com/golang/go/src go1.25.1 net/Resolver#PreferGo.: true, |
| 267 | Dialscip-go gomod github.com/golang/go/src go1.25.1 net/Resolver#Dial.: func(ctx contextscip-go gomod github.com/golang/go/src go1.25.1 context/.Contextscip-go gomod github.com/golang/go/src go1.25.1 context/Context#, _, _ string) (netscip-go gomod github.com/golang/go/src go1.25.1 net/.Connscip-go gomod github.com/golang/go/src go1.25.1 net/Conn#, error) { |
| 268 | //nolint:gosec |
| 269 | addr := h.Resolverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Resolver..netAddrsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/UpstreamResolver#netAddrs.[weakrandscip-go gomod github.com/golang/go/src go1.25.1 `math/rand/v2`/.IntNscip-go gomod github.com/golang/go/src go1.25.1 `math/rand/v2`/IntN().(len(h.Resolverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Resolver..netAddrsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/UpstreamResolver#netAddrs.))] |
| 270 | return d.DialContextscip-go gomod github.com/golang/go/src go1.25.1 net/Dialer#DialContext().(ctx, addr.Networkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#Network., addr.JoinHostPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NetworkAddress#JoinHostPort().(0)) |
| 271 | }, |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | dialContext := func(ctx contextscip-go gomod github.com/golang/go/src go1.25.1 context/.Contextscip-go gomod github.com/golang/go/src go1.25.1 context/Context#, network, address string) (netscip-go gomod github.com/golang/go/src go1.25.1 net/.Connscip-go gomod github.com/golang/go/src go1.25.1 net/Conn#, error) { |
| 276 | // The network is usually tcp, and the address is the host in http.Request.URL.Host |
| 277 | // and that's been overwritten in directRequest |
| 278 | // However, if proxy is used according to http.ProxyFromEnvironment or proxy providers, |
| 279 | // address will be the address of the proxy server. |
| 280 | |
| 281 | // This means we can safely use the address in dialInfo if proxy is not used (the address and network will be same any way) |
| 282 | // or if the upstream is unix (because there is no way socks or http proxy can be used for unix address). |
| 283 | if dialInfo, ok := GetDialInfoscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/GetDialInfo().(ctx); ok { |
| 284 | if caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.GetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/GetVar().(ctx, proxyVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/proxyVarKey.) == nil || stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.1 strings/HasPrefix().(dialInfo.Networkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/DialInfo#Network., "unix") { |
| 285 | network = dialInfo.Networkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/DialInfo#Network. |
| 286 | address = dialInfo.Addressscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/DialInfo#Address. |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | conn, err := dialer.DialContextscip-go gomod github.com/golang/go/src go1.25.1 net/Dialer#DialContext().(ctx, network, address) |
| 291 | if err != nil { |
| 292 | // identify this error as one that occurred during |
| 293 | // dialing, which can be important when trying to |
| 294 | // decide whether to retry a request |
| 295 | return nil, DialErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/DialError#{err} |
| 296 | } |
| 297 | |
| 298 | if h.ProxyProtocolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#ProxyProtocol. != "" { |
| 299 | proxyProtocolInfo, ok := caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.GetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/GetVar().(ctx, proxyProtocolInfoVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/proxyProtocolInfoVarKey.).(ProxyProtocolInfoscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ProxyProtocolInfo#) |
| 300 | if !ok { |
| 301 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("failed to get proxy protocol info from context") |
| 302 | } |
| 303 | var proxyv byte |
| 304 | switch h.ProxyProtocolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#ProxyProtocol. { |
| 305 | case "v1": |
| 306 | proxyv = 1 |
| 307 | case "v2": |
| 308 | proxyv = 2 |
| 309 | default: |
| 310 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("unexpected proxy protocol version") |
| 311 | } |
| 312 | |
| 313 | // The src and dst have to be of the same address family. As we don't know the original |
| 314 | // dst address (it's kind of impossible to know) and this address is generally of very |
| 315 | // little interest, we just set it to all zeros. |
| 316 | var destAddr netscip-go gomod github.com/golang/go/src go1.25.1 net/.Addrscip-go gomod github.com/golang/go/src go1.25.1 net/Addr# |
| 317 | switch { |
| 318 | case proxyProtocolInfo.AddrPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ProxyProtocolInfo#AddrPort..Addrscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/AddrPort#Addr().().Is4scip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Addr#Is4().(): |
| 319 | destAddr = &netscip-go gomod github.com/golang/go/src go1.25.1 net/.TCPAddrscip-go gomod github.com/golang/go/src go1.25.1 net/TCPAddr#{ |
| 320 | IPscip-go gomod github.com/golang/go/src go1.25.1 net/TCPAddr#IP.: netscip-go gomod github.com/golang/go/src go1.25.1 net/.IPv4zeroscip-go gomod github.com/golang/go/src go1.25.1 net/IPv4zero., |
| 321 | } |
| 322 | case proxyProtocolInfo.AddrPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ProxyProtocolInfo#AddrPort..Addrscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/AddrPort#Addr().().Is6scip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Addr#Is6().(): |
| 323 | destAddr = &netscip-go gomod github.com/golang/go/src go1.25.1 net/.TCPAddrscip-go gomod github.com/golang/go/src go1.25.1 net/TCPAddr#{ |
| 324 | IPscip-go gomod github.com/golang/go/src go1.25.1 net/TCPAddr#IP.: netscip-go gomod github.com/golang/go/src go1.25.1 net/.IPv6zeroscip-go gomod github.com/golang/go/src go1.25.1 net/IPv6zero., |
| 325 | } |
| 326 | default: |
| 327 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("unexpected remote addr type in proxy protocol info") |
| 328 | } |
| 329 | sourceAddr := &netscip-go gomod github.com/golang/go/src go1.25.1 net/.TCPAddrscip-go gomod github.com/golang/go/src go1.25.1 net/TCPAddr#{ |
| 330 | IPscip-go gomod github.com/golang/go/src go1.25.1 net/TCPAddr#IP.: proxyProtocolInfo.AddrPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ProxyProtocolInfo#AddrPort..Addrscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/AddrPort#Addr().().AsSlicescip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Addr#AsSlice().(), |
| 331 | Portscip-go gomod github.com/golang/go/src go1.25.1 net/TCPAddr#Port.: int(proxyProtocolInfo.AddrPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ProxyProtocolInfo#AddrPort..Portscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/AddrPort#Port().()), |
| 332 | Zonescip-go gomod github.com/golang/go/src go1.25.1 net/TCPAddr#Zone.: proxyProtocolInfo.AddrPortscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ProxyProtocolInfo#AddrPort..Addrscip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/AddrPort#Addr().().Zonescip-go gomod github.com/golang/go/src go1.25.1 `net/netip`/Addr#Zone().(), |
| 333 | } |
| 334 | header := proxyprotoscip-go gomod github.com/pires/go-proxyproto v0.12.0 `github.com/pires/go-proxyproto`/.HeaderProxyFromAddrsscip-go gomod github.com/pires/go-proxyproto v0.12.0 `github.com/pires/go-proxyproto`/HeaderProxyFromAddrs().(proxyv, sourceAddr, destAddr) |
| 335 | |
| 336 | // retain the log message structure |
| 337 | switch h.ProxyProtocolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#ProxyProtocol. { |
| 338 | case "v1": |
| 339 | caddyCtx.Loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#Logger().().Debugscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Debug().("sending proxy protocol header v1", zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Anyscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Any().("header", header)) |
| 340 | case "v2": |
| 341 | caddyCtx.Loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#Logger().().Debugscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Debug().("sending proxy protocol header v2", zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Anyscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Any().("header", header)) |
| 342 | } |
| 343 | |
| 344 | _, err = header.WriteToscip-go gomod github.com/pires/go-proxyproto v0.12.0 `github.com/pires/go-proxyproto`/Header#WriteTo().(conn) |
| 345 | if err != nil { |
| 346 | // identify this error as one that occurred during |
| 347 | // dialing, which can be important when trying to |
| 348 | // decide whether to retry a request |
| 349 | return nil, DialErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/DialError#{err} |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | // if read/write timeouts are configured and this is a TCP connection, |
| 354 | // enforce the timeouts by wrapping the connection with our own type |
| 355 | if tcpConn, ok := conn.(*netscip-go gomod github.com/golang/go/src go1.25.1 net/.TCPConnscip-go gomod github.com/golang/go/src go1.25.1 net/TCPConn#); ok && (h.ReadTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#ReadTimeout. > 0 || h.WriteTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#WriteTimeout. > 0) { |
| 356 | conn = &tcpRWTimeoutConnscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#{ |
| 357 | TCPConnscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#TCPConn.: tcpConn, |
| 358 | readTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#readTimeout.: timescip-go gomod github.com/golang/go/src go1.25.1 time/.Durationscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#(h.ReadTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#ReadTimeout.), |
| 359 | writeTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#writeTimeout.: timescip-go gomod github.com/golang/go/src go1.25.1 time/.Durationscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#(h.WriteTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#WriteTimeout.), |
| 360 | loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#logger.: caddyCtx.Loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#Logger().(), |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | return conn, nil |
| 365 | } |
| 366 | |
| 367 | // negotiate any HTTP/SOCKS proxy for the HTTP transport |
| 368 | proxy := httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.ProxyFromEnvironmentscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ProxyFromEnvironment(). |
| 369 | if h.ForwardProxyURLscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#ForwardProxyURL. != "" { |
| 370 | caddyCtx.Loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#Logger().().Warnscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Warn().("forward_proxy_url is deprecated; use network_proxy instead") |
| 371 | u := networkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/internal/network`/.ProxyFromURLscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/internal/network`/ProxyFromURL#{URLscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/internal/network`/ProxyFromURL#URL.: h.ForwardProxyURLscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#ForwardProxyURL.} |
| 372 | h.NetworkProxyRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#NetworkProxyRaw. = caddyconfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/.JSONModuleObjectscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/caddyconfig`/JSONModuleObject().(u, "from", "url", nil) |
| 373 | } |
| 374 | if len(h.NetworkProxyRawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#NetworkProxyRaw.) != 0 { |
| 375 | proxyMod, err := caddyCtx.LoadModulescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#LoadModule().(h, "NetworkProxyRaw") |
| 376 | if err != nil { |
| 377 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("failed to load network_proxy module: %v", err) |
| 378 | } |
| 379 | if m, ok := proxyMod.(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ProxyFuncProducerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ProxyFuncProducer#); ok { |
| 380 | proxy = m.ProxyFuncscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ProxyFuncProducer#ProxyFunc.() |
| 381 | } else { |
| 382 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("network_proxy module is not `(func(*http.Request) (*url.URL, error))``") |
| 383 | } |
| 384 | } |
| 385 | // we need to keep track if a proxy is used for a request |
| 386 | proxyWrapper := func(req *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#) (*urlscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/.URLscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/URL#, error) { |
| 387 | if proxy == nil { |
| 388 | return nil, nil |
| 389 | } |
| 390 | u, err := proxy(req) |
| 391 | if u == nil || err != nil { |
| 392 | return u, err |
| 393 | } |
| 394 | // there must be a proxy for this request |
| 395 | caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.SetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/SetVar().(req.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), proxyVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/proxyVarKey., u) |
| 396 | return u, nil |
| 397 | } |
| 398 | |
| 399 | rt := &httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Transportscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#{ |
| 400 | Proxyscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#Proxy.: proxyWrapper, |
| 401 | DialContextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#DialContext.: dialContext, |
| 402 | MaxConnsPerHostscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#MaxConnsPerHost.: h.MaxConnsPerHostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#MaxConnsPerHost., |
| 403 | ResponseHeaderTimeoutscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#ResponseHeaderTimeout.: timescip-go gomod github.com/golang/go/src go1.25.1 time/.Durationscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#(h.ResponseHeaderTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#ResponseHeaderTimeout.), |
| 404 | ExpectContinueTimeoutscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#ExpectContinueTimeout.: timescip-go gomod github.com/golang/go/src go1.25.1 time/.Durationscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#(h.ExpectContinueTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#ExpectContinueTimeout.), |
| 405 | MaxResponseHeaderBytesscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#MaxResponseHeaderBytes.: h.MaxResponseHeaderSizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#MaxResponseHeaderSize., |
| 406 | WriteBufferSizescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#WriteBufferSize.: h.WriteBufferSizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#WriteBufferSize., |
| 407 | ReadBufferSizescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#ReadBufferSize.: h.ReadBufferSizescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#ReadBufferSize., |
| 408 | } |
| 409 | |
| 410 | if h.TLSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#TLS. != nil { |
| 411 | rt.TLSHandshakeTimeoutscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#TLSHandshakeTimeout. = timescip-go gomod github.com/golang/go/src go1.25.1 time/.Durationscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#(h.TLSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#TLS..HandshakeTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#HandshakeTimeout.) |
| 412 | var err error |
| 413 | rt.TLSClientConfigscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#TLSClientConfig., err = h.TLSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#TLS..MakeTLSClientConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#MakeTLSClientConfig().(caddyCtx) |
| 414 | if err != nil { |
| 415 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("making TLS client config: %v", err) |
| 416 | } |
| 417 | |
| 418 | serverNameHasPlaceholder := stringsscip-go gomod github.com/golang/go/src go1.25.1 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.1 strings/Contains().(h.TLSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#TLS..ServerNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ServerName., "{") |
| 419 | |
| 420 | // We need to use custom DialTLSContext if: |
| 421 | // 1. ServerName has a placeholder that needs to be replaced at request-time, OR |
| 422 | // 2. ProxyProtocol is enabled, because req.URL.Host is modified to include |
| 423 | // client address info with "->" separator which breaks Go's address parsing |
| 424 | if serverNameHasPlaceholder || h.ProxyProtocolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#ProxyProtocol. != "" { |
| 425 | rt.DialTLSContextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#DialTLSContext. = func(ctx contextscip-go gomod github.com/golang/go/src go1.25.1 context/.Contextscip-go gomod github.com/golang/go/src go1.25.1 context/Context#, network, addr string) (netscip-go gomod github.com/golang/go/src go1.25.1 net/.Connscip-go gomod github.com/golang/go/src go1.25.1 net/Conn#, error) { |
| 426 | // reuses the dialer from above to establish a plaintext connection |
| 427 | conn, err := dialContext(ctx, network, addr) |
| 428 | if err != nil { |
| 429 | return nil, err |
| 430 | } |
| 431 | |
| 432 | // but add our own handshake logic |
| 433 | tlsConfig := rt.TLSClientConfigscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#TLSClientConfig..Clonescip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Config#Clone().() |
| 434 | if serverNameHasPlaceholder { |
| 435 | repl := ctx.Valuescip-go gomod github.com/golang/go/src go1.25.1 context/Context#Value().(caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ReplacerCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ReplacerCtxKey.).(*caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Replacerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#) |
| 436 | tlsConfig.ServerNamescip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Config#ServerName. = repl.ReplaceAllscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#ReplaceAll().(tlsConfig.ServerNamescip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Config#ServerName., "") |
| 437 | } |
| 438 | |
| 439 | // h1 only |
| 440 | if caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.GetVarscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/GetVar().(ctx, tlsH1OnlyVarKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tlsH1OnlyVarKey.) == true { |
| 441 | // stdlib does this |
| 442 | // https://github.com/golang/go/blob/4837fbe4145cd47b43eed66fee9eed9c2b988316/src/net/http/transport.go#L1701 |
| 443 | tlsConfig.NextProtosscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Config#NextProtos. = nil |
| 444 | } |
| 445 | |
| 446 | tlsConn := tlsscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/.Clientscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Client().(conn, tlsConfig) |
| 447 | |
| 448 | // complete the handshake before returning the connection |
| 449 | if rt.TLSHandshakeTimeoutscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#TLSHandshakeTimeout. != 0 { |
| 450 | var cancel contextscip-go gomod github.com/golang/go/src go1.25.1 context/.CancelFuncscip-go gomod github.com/golang/go/src go1.25.1 context/CancelFunc# |
| 451 | ctx, cancel = contextscip-go gomod github.com/golang/go/src go1.25.1 context/.WithTimeoutCausescip-go gomod github.com/golang/go/src go1.25.1 context/WithTimeoutCause().(ctx, rt.TLSHandshakeTimeoutscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#TLSHandshakeTimeout., fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("HTTP transport TLS handshake %ds timeout", int(rt.TLSHandshakeTimeoutscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#TLSHandshakeTimeout..Secondsscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#Seconds().()))) |
| 452 | defer cancel() |
| 453 | } |
| 454 | err = tlsConn.HandshakeContextscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Conn#HandshakeContext().(ctx) |
| 455 | if err != nil { |
| 456 | _ = tlsConn.Closescip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Conn#Close().() |
| 457 | return nil, err |
| 458 | } |
| 459 | return tlsConn, nil |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | if h.KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#KeepAlive. != nil { |
| 465 | // according to https://pkg.go.dev/net#Dialer.KeepAliveConfig, |
| 466 | // KeepAlive is ignored if KeepAliveConfig.Enable is true. |
| 467 | // If configured to 0, a system-dependent default is used. |
| 468 | // To disable tcp keepalive, choose a negative value, |
| 469 | // so KeepAliveConfig.Enable is false and KeepAlive is negative. |
| 470 | |
| 471 | // This is different from http keepalive where a tcp connection |
| 472 | // can transfer multiple http requests/responses. |
| 473 | dialer.KeepAlivescip-go gomod github.com/golang/go/src go1.25.1 net/Dialer#KeepAlive. = timescip-go gomod github.com/golang/go/src go1.25.1 time/.Durationscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#(h.KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#KeepAlive..ProbeIntervalscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive#ProbeInterval.) |
| 474 | dialer.KeepAliveConfigscip-go gomod github.com/golang/go/src go1.25.1 net/Dialer#KeepAliveConfig. = netscip-go gomod github.com/golang/go/src go1.25.1 net/.KeepAliveConfigscip-go gomod github.com/golang/go/src go1.25.1 net/KeepAliveConfig#{ |
| 475 | Enablescip-go gomod github.com/golang/go/src go1.25.1 net/KeepAliveConfig#Enable.: h.KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#KeepAlive..ProbeIntervalscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive#ProbeInterval. > 0, |
| 476 | Intervalscip-go gomod github.com/golang/go/src go1.25.1 net/KeepAliveConfig#Interval.: timescip-go gomod github.com/golang/go/src go1.25.1 time/.Durationscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#(h.KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#KeepAlive..ProbeIntervalscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive#ProbeInterval.), |
| 477 | } |
| 478 | if h.KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#KeepAlive..Enabledscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive#Enabled. != nil { |
| 479 | rt.DisableKeepAlivesscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#DisableKeepAlives. = !*h.KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#KeepAlive..Enabledscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive#Enabled. |
| 480 | } |
| 481 | rt.MaxIdleConnsscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#MaxIdleConns. = h.KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#KeepAlive..MaxIdleConnsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive#MaxIdleConns. |
| 482 | rt.MaxIdleConnsPerHostscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#MaxIdleConnsPerHost. = h.KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#KeepAlive..MaxIdleConnsPerHostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive#MaxIdleConnsPerHost. |
| 483 | rt.IdleConnTimeoutscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#IdleConnTimeout. = timescip-go gomod github.com/golang/go/src go1.25.1 time/.Durationscip-go gomod github.com/golang/go/src go1.25.1 time/Duration#(h.KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#KeepAlive..IdleConnTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive#IdleConnTimeout.) |
| 484 | } |
| 485 | |
| 486 | if h.Compressionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Compression. != nil { |
| 487 | rt.DisableCompressionscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#DisableCompression. = !*h.Compressionscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Compression. |
| 488 | } |
| 489 | |
| 490 | // configure HTTP/3 transport if enabled; however, this does not |
| 491 | // automatically fall back to lower versions like most web browsers |
| 492 | // do (that'd add latency and complexity, besides, we expect that |
| 493 | // site owners control the backends), so it must be exclusive |
| 494 | if len(h.Versionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Versions.) == 1 && h.Versionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Versions.[0] == "3" { |
| 495 | h.h3Transportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#h3Transport. = new(http3scip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/.Transportscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/Transport#) |
| 496 | if h.TLSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#TLS. != nil { |
| 497 | var err error |
| 498 | h.h3Transportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#h3Transport..TLSClientConfigscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/Transport#TLSClientConfig., err = h.TLSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#TLS..MakeTLSClientConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#MakeTLSClientConfig().(caddyCtx) |
| 499 | if err != nil { |
| 500 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("making TLS client config for HTTP/3 transport: %v", err) |
| 501 | } |
| 502 | } |
| 503 | } else if len(h.Versionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Versions.) > 1 && slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/.Containsscip-go gomod github.com/golang/go/src go1.25.1 slices/Contains().(h.Versionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Versions., "3") { |
| 504 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("if HTTP/3 is enabled to the upstream, no other HTTP versions are supported") |
| 505 | } |
| 506 | |
| 507 | // if h2/c is enabled, configure it explicitly |
| 508 | if slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/.Containsscip-go gomod github.com/golang/go/src go1.25.1 slices/Contains().(h.Versionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Versions., "2") || slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/.Containsscip-go gomod github.com/golang/go/src go1.25.1 slices/Contains().(h.Versionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Versions., "h2c") { |
| 509 | if err := http2scip-go gomod golang.org/x/net v0.55.0 `golang.org/x/net/http2`/.ConfigureTransportscip-go gomod golang.org/x/net v0.55.0 `golang.org/x/net/http2`/ConfigureTransport().(rt); err != nil { |
| 510 | return nil, err |
| 511 | } |
| 512 | |
| 513 | // DisableCompression from h2 is configured by http2.ConfigureTransport |
| 514 | // Likewise, DisableKeepAlives from h1 is used too. |
| 515 | |
| 516 | // Protocols field is only used when the request is not using TLS, |
| 517 | // http1/2 over tls is still allowed |
| 518 | if slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/.Containsscip-go gomod github.com/golang/go/src go1.25.1 slices/Contains().(h.Versionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Versions., "h2c") { |
| 519 | rt.Protocolsscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#Protocols. = new(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Protocolsscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Protocols#) |
| 520 | rt.Protocolsscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#Protocols..SetUnencryptedHTTP2scip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Protocols#SetUnencryptedHTTP2().(true) |
| 521 | rt.Protocolsscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#Protocols..SetHTTP1scip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Protocols#SetHTTP1().(false) |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | return rt, nil |
| 526 | } |
| 527 | |
| 528 | // RequestHeaderOps implements TransportHeaderOpsProvider. It returns header |
| 529 | // operations for requests when the transport's configuration indicates they |
| 530 | // should be applied. In particular, when TLS is enabled for this transport, |
| 531 | // return an operation to set the Host header to the upstream host:port |
| 532 | // placeholder so HTTPS upstreams get the proper Host by default. |
| 533 | // |
| 534 | // Note: this is a provision-time hook; the Handler will call this during |
| 535 | // its Provision and cache the resulting HeaderOps. The HeaderOps are |
| 536 | // applied per-request (so placeholders are expanded at request time). |
| 537 | func (h *HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#) RequestHeaderOpsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#RequestHeaderOps().() *headersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/headers`/.HeaderOpsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/headers`/HeaderOps# { |
| 538 | // If TLS is not configured for this transport, don't inject Host |
| 539 | // defaults. TLS being non-nil indicates HTTPS to the upstream. |
| 540 | if h.TLSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#TLS. == nil { |
| 541 | return nil |
| 542 | } |
| 543 | return &headersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/headers`/.HeaderOpsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/headers`/HeaderOps#{ |
| 544 | Setscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/headers`/HeaderOps#Set.: httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Headerscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Header#{ |
| 545 | "Host": []string{"{http.reverse_proxy.upstream.hostport}"}, |
| 546 | }, |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | // RoundTrip implements http.RoundTripper. |
| 551 | func (h *HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#) RoundTripscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#RoundTrip().(req *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#) (*httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Responsescip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Response#, error) { |
| 552 | h.SetSchemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#SetScheme().(req) |
| 553 | |
| 554 | // use HTTP/3 if enabled (TODO: This is EXPERIMENTAL) |
| 555 | if h.h3Transportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#h3Transport. != nil { |
| 556 | return h.h3Transportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#h3Transport..RoundTripscip-go gomod github.com/quic-go/quic-go v0.59.1 `github.com/quic-go/quic-go/http3`/Transport#RoundTrip().(req) |
| 557 | } |
| 558 | |
| 559 | return h.Transportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Transport..RoundTripscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#RoundTrip().(req) |
| 560 | } |
| 561 | |
| 562 | // SetScheme ensures that the outbound request req |
| 563 | // has the scheme set in its URL; the underlying |
| 564 | // http.Transport requires a scheme to be set. |
| 565 | // |
| 566 | // This method may be used by other transport modules |
| 567 | // that wrap/use this one. |
| 568 | func (h *HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#) SetSchemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#SetScheme().(req *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#) { |
| 569 | if req.URLscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#URL..Schemescip-go gomod github.com/golang/go/src go1.25.1 `net/url`/URL#Scheme. != "" { |
| 570 | return |
| 571 | } |
| 572 | if h.shouldUseTLSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#shouldUseTLS().(req) { |
| 573 | req.URLscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#URL..Schemescip-go gomod github.com/golang/go/src go1.25.1 `net/url`/URL#Scheme. = "https" |
| 574 | } else { |
| 575 | req.URLscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#URL..Schemescip-go gomod github.com/golang/go/src go1.25.1 `net/url`/URL#Scheme. = "http" |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | // shouldUseTLS returns true if TLS should be used for req. |
| 580 | func (h *HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#) shouldUseTLSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#shouldUseTLS().(req *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#) bool { |
| 581 | if h.TLSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#TLS. == nil { |
| 582 | return false |
| 583 | } |
| 584 | |
| 585 | port := req.URLscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#URL..Portscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/URL#Port().() |
| 586 | return !slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/.Containsscip-go gomod github.com/golang/go/src go1.25.1 slices/Contains().(h.TLSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#TLS..ExceptPortsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ExceptPorts., port) |
| 587 | } |
| 588 | |
| 589 | // TLSEnabled returns true if TLS is enabled. |
| 590 | func (h HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#) TLSEnabledscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#TLSEnabled().() bool { |
| 591 | return h.TLSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#TLS. != nil |
| 592 | } |
| 593 | |
| 594 | // EnableTLS enables TLS on the transport. |
| 595 | func (h *HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#) EnableTLSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#EnableTLS().(base *TLSConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#) error { |
| 596 | h.TLSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#TLS. = base |
| 597 | return nil |
| 598 | } |
| 599 | |
| 600 | // EnableH2C enables H2C (HTTP/2 over Cleartext) on the transport. |
| 601 | func (h *HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#) EnableH2Cscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#EnableH2C().() error { |
| 602 | h.Versionsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Versions. = []string{"h2c", "2"} |
| 603 | return nil |
| 604 | } |
| 605 | |
| 606 | // OverrideHealthCheckScheme overrides the scheme of the given URL |
| 607 | // used for health checks. |
| 608 | func (h HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#) OverrideHealthCheckSchemescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#OverrideHealthCheckScheme().(base *urlscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/.URLscip-go gomod github.com/golang/go/src go1.25.1 `net/url`/URL#, port string) { |
| 609 | // if tls is enabled and the port isn't in the except list, use HTTPs |
| 610 | if h.TLSEnabledscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#TLSEnabled().() && !slicesscip-go gomod github.com/golang/go/src go1.25.1 slices/.Containsscip-go gomod github.com/golang/go/src go1.25.1 slices/Contains().(h.TLSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#TLS..ExceptPortsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ExceptPorts., port) { |
| 611 | base.Schemescip-go gomod github.com/golang/go/src go1.25.1 `net/url`/URL#Scheme. = "https" |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | // ProxyProtocolEnabled returns true if proxy protocol is enabled. |
| 616 | func (h HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#) ProxyProtocolEnabledscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#ProxyProtocolEnabled().() bool { |
| 617 | return h.ProxyProtocolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#ProxyProtocol. != "" |
| 618 | } |
| 619 | |
| 620 | // Cleanup implements caddy.CleanerUpper and closes any idle connections. |
| 621 | func (h HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#) Cleanupscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Cleanup().() error { |
| 622 | if h.Transportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Transport. == nil { |
| 623 | return nil |
| 624 | } |
| 625 | h.Transportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#Transport..CloseIdleConnectionsscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Transport#CloseIdleConnections().() |
| 626 | return nil |
| 627 | } |
| 628 | |
| 629 | // TLSConfig holds configuration related to the TLS configuration for the |
| 630 | // transport/client. |
| 631 | type TLSConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig# struct { |
| 632 | // Certificate authority module which provides the certificate pool of trusted certificates |
| 633 | CARawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#CARaw. jsonscip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/.RawMessagescip-go gomod github.com/golang/go/src go1.25.1 `encoding/json`/RawMessage# `json:"ca,omitempty" caddy:"namespace=tls.ca_pool.source inline_key=provider"` |
| 634 | |
| 635 | // Deprecated: Use the `ca` field with the `tls.ca_pool.source.inline` module instead. |
| 636 | // Optional list of base64-encoded DER-encoded CA certificates to trust. |
| 637 | RootCAPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#RootCAPool. []string `json:"root_ca_pool,omitempty"` |
| 638 | |
| 639 | // Deprecated: Use the `ca` field with the `tls.ca_pool.source.file` module instead. |
| 640 | // List of PEM-encoded CA certificate files to add to the same trust |
| 641 | // store as RootCAPool (or root_ca_pool in the JSON). |
| 642 | RootCAPEMFilesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#RootCAPEMFiles. []string `json:"root_ca_pem_files,omitempty"` |
| 643 | |
| 644 | // PEM-encoded client certificate filename to present to servers. |
| 645 | ClientCertificateFilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ClientCertificateFile. string `json:"client_certificate_file,omitempty"` |
| 646 | |
| 647 | // PEM-encoded key to use with the client certificate. |
| 648 | ClientCertificateKeyFilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ClientCertificateKeyFile. string `json:"client_certificate_key_file,omitempty"` |
| 649 | |
| 650 | // If specified, Caddy will use and automate a client certificate |
| 651 | // with this subject name. |
| 652 | ClientCertificateAutomatescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ClientCertificateAutomate. string `json:"client_certificate_automate,omitempty"` |
| 653 | |
| 654 | // If true, TLS verification of server certificates will be disabled. |
| 655 | // This is insecure and may be removed in the future. Do not use this |
| 656 | // option except in testing or local development environments. |
| 657 | InsecureSkipVerifyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#InsecureSkipVerify. bool `json:"insecure_skip_verify,omitempty"` |
| 658 | |
| 659 | // The duration to allow a TLS handshake to a server. Default: No timeout. |
| 660 | HandshakeTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#HandshakeTimeout. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Durationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Duration# `json:"handshake_timeout,omitempty"` |
| 661 | |
| 662 | // The server name used when verifying the certificate received in the TLS |
| 663 | // handshake. By default, this will use the upstream address' host part. |
| 664 | // You only need to override this if your upstream address does not match the |
| 665 | // certificate the upstream is likely to use. For example if the upstream |
| 666 | // address is an IP address, then you would need to configure this to the |
| 667 | // hostname being served by the upstream server. Currently, this does not |
| 668 | // support placeholders because the TLS config is not provisioned on each |
| 669 | // connection, so a static value must be used. |
| 670 | ServerNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ServerName. string `json:"server_name,omitempty"` |
| 671 | |
| 672 | // TLS renegotiation level. TLS renegotiation is the act of performing |
| 673 | // subsequent handshakes on a connection after the first. |
| 674 | // The level can be: |
| 675 | // - "never": (the default) disables renegotiation. |
| 676 | // - "once": allows a remote server to request renegotiation once per connection. |
| 677 | // - "freely": allows a remote server to repeatedly request renegotiation. |
| 678 | Renegotiationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#Renegotiation. string `json:"renegotiation,omitempty"` |
| 679 | |
| 680 | // Skip TLS ports specifies a list of upstream ports on which TLS should not be |
| 681 | // attempted even if it is configured. Handy when using dynamic upstreams that |
| 682 | // return HTTP and HTTPS endpoints too. |
| 683 | // When specified, TLS will automatically be configured on the transport. |
| 684 | // The value can be a list of any valid tcp port numbers, default empty. |
| 685 | ExceptPortsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ExceptPorts. []string `json:"except_ports,omitempty"` |
| 686 | |
| 687 | // The list of elliptic curves to support. Caddy's |
| 688 | // defaults are modern and secure. |
| 689 | Curvesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#Curves. []string `json:"curves,omitempty"` |
| 690 | } |
| 691 | |
| 692 | // MakeTLSClientConfig returns a tls.Config usable by a client to a backend. |
| 693 | // If there is no custom TLS configuration, a nil config may be returned. |
| 694 | func (t *TLSConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#) MakeTLSClientConfigscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#MakeTLSClientConfig().(ctx caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Contextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#) (*tlsscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/.Configscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Config#, error) { |
| 695 | cfg := new(tlsscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/.Configscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Config#) |
| 696 | |
| 697 | // client auth |
| 698 | if t.ClientCertificateFilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ClientCertificateFile. != "" && t.ClientCertificateKeyFilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ClientCertificateKeyFile. == "" { |
| 699 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("client_certificate_file specified without client_certificate_key_file") |
| 700 | } |
| 701 | if t.ClientCertificateFilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ClientCertificateFile. == "" && t.ClientCertificateKeyFilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ClientCertificateKeyFile. != "" { |
| 702 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("client_certificate_key_file specified without client_certificate_file") |
| 703 | } |
| 704 | if t.ClientCertificateFilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ClientCertificateFile. != "" && t.ClientCertificateKeyFilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ClientCertificateKeyFile. != "" { |
| 705 | cert, err := tlsscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/.LoadX509KeyPairscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/LoadX509KeyPair().(t.ClientCertificateFilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ClientCertificateFile., t.ClientCertificateKeyFilescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ClientCertificateKeyFile.) |
| 706 | if err != nil { |
| 707 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("loading client certificate key pair: %v", err) |
| 708 | } |
| 709 | cfg.Certificatesscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Config#Certificates. = []tlsscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/.Certificatescip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Certificate#{cert} |
| 710 | } |
| 711 | if t.ClientCertificateAutomatescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ClientCertificateAutomate. != "" { |
| 712 | // TODO: use or enable ctx.IdentityCredentials() ... |
| 713 | tlsAppIface, err := ctx.Appscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#App().("tls") |
| 714 | if err != nil { |
| 715 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("getting tls app: %v", err) |
| 716 | } |
| 717 | tlsApp := tlsAppIface.(*caddytlsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/.TLSscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/TLS#) |
| 718 | err = tlsApp.Managescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/TLS#Manage().(map[string]struct{}{t.ClientCertificateAutomatescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ClientCertificateAutomate.: {}}) |
| 719 | if err != nil { |
| 720 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("managing client certificate: %v", err) |
| 721 | } |
| 722 | cfg.GetClientCertificatescip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Config#GetClientCertificate. = func(cri *tlsscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/.CertificateRequestInfoscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/CertificateRequestInfo#) (*tlsscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/.Certificatescip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Certificate#, error) { |
| 723 | certs := caddytlsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/.AllMatchingCertificatesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/AllMatchingCertificates().(t.ClientCertificateAutomatescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ClientCertificateAutomate.) |
| 724 | var err error |
| 725 | for _, cert := range certs { |
| 726 | certCertificate := cert.Certificatescip-go gomod github.com/caddyserver/certmagic v0.25.3 `github.com/caddyserver/certmagic`/Certificate#Certificate. // avoid taking address of iteration variable (gosec warning) |
| 727 | err = cri.SupportsCertificatescip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/CertificateRequestInfo#SupportsCertificate().(&certCertificate) |
| 728 | if err == nil { |
| 729 | return &cert.Certificatescip-go gomod github.com/caddyserver/certmagic v0.25.3 `github.com/caddyserver/certmagic`/Certificate#Certificate., nil |
| 730 | } |
| 731 | } |
| 732 | if err == nil { |
| 733 | err = fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("no client certificate found for automate name: %s", t.ClientCertificateAutomatescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ClientCertificateAutomate.) |
| 734 | } |
| 735 | return nil, err |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | // trusted root CAs |
| 740 | if len(t.RootCAPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#RootCAPool.) > 0 || len(t.RootCAPEMFilesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#RootCAPEMFiles.) > 0 { |
| 741 | ctx.Loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#Logger().().Warnscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Warn().("root_ca_pool and root_ca_pem_files are deprecated. Use one of the tls.ca_pool.source modules instead") |
| 742 | rootPool := x509scip-go gomod github.com/golang/go/src go1.25.1 `crypto/x509`/.NewCertPoolscip-go gomod github.com/golang/go/src go1.25.1 `crypto/x509`/NewCertPool().() |
| 743 | for _, encodedCACert := range t.RootCAPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#RootCAPool. { |
| 744 | caCert, err := decodeBase64DERCertscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/decodeBase64DERCert().(encodedCACert) |
| 745 | if err != nil { |
| 746 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("parsing CA certificate: %v", err) |
| 747 | } |
| 748 | rootPool.AddCertscip-go gomod github.com/golang/go/src go1.25.1 `crypto/x509`/CertPool#AddCert().(caCert) |
| 749 | } |
| 750 | for _, pemFile := range t.RootCAPEMFilesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#RootCAPEMFiles. { |
| 751 | pemData, err := osscip-go gomod github.com/golang/go/src go1.25.1 os/.ReadFilescip-go gomod github.com/golang/go/src go1.25.1 os/ReadFile().(pemFile) |
| 752 | if err != nil { |
| 753 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("failed reading ca cert: %v", err) |
| 754 | } |
| 755 | rootPool.AppendCertsFromPEMscip-go gomod github.com/golang/go/src go1.25.1 `crypto/x509`/CertPool#AppendCertsFromPEM().(pemData) |
| 756 | } |
| 757 | cfg.RootCAsscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Config#RootCAs. = rootPool |
| 758 | } |
| 759 | |
| 760 | if t.CARawscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#CARaw. != nil { |
| 761 | if len(t.RootCAPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#RootCAPool.) > 0 || len(t.RootCAPEMFilesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#RootCAPEMFiles.) > 0 { |
| 762 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("conflicting config for Root CA pool") |
| 763 | } |
| 764 | caRaw, err := ctx.LoadModulescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Context#LoadModule().(t, "CARaw") |
| 765 | if err != nil { |
| 766 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("failed to load ca module: %v", err) |
| 767 | } |
| 768 | ca, ok := caRaw.(caddytlsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/.CAscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/CA#) |
| 769 | if !ok { |
| 770 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("CA module '%s' is not a certificate pool provider", ca) |
| 771 | } |
| 772 | cfg.RootCAsscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Config#RootCAs. = ca.CertPoolscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/CA#CertPool.() |
| 773 | } |
| 774 | |
| 775 | // Renegotiation |
| 776 | switch t.Renegotiationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#Renegotiation. { |
| 777 | case "never", "": |
| 778 | cfg.Renegotiationscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Config#Renegotiation. = tlsscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/.RenegotiateNeverscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/RenegotiateNever. |
| 779 | case "once": |
| 780 | cfg.Renegotiationscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Config#Renegotiation. = tlsscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/.RenegotiateOnceAsClientscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/RenegotiateOnceAsClient. |
| 781 | case "freely": |
| 782 | cfg.Renegotiationscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Config#Renegotiation. = tlsscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/.RenegotiateFreelyAsClientscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/RenegotiateFreelyAsClient. |
| 783 | default: |
| 784 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25.1 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25.1 fmt/Errorf().("invalid TLS renegotiation level: %v", t.Renegotiationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#Renegotiation.) |
| 785 | } |
| 786 | |
| 787 | // override for the server name used verify the TLS handshake |
| 788 | cfg.ServerNamescip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Config#ServerName. = t.ServerNamescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#ServerName. |
| 789 | |
| 790 | // throw all security out the window |
| 791 | cfg.InsecureSkipVerifyscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Config#InsecureSkipVerify. = t.InsecureSkipVerifyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#InsecureSkipVerify. |
| 792 | |
| 793 | curvesAdded := make(map[tlsscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/.CurveIDscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/CurveID#]struct{}) |
| 794 | for _, curveName := range t.Curvesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSConfig#Curves. { |
| 795 | curveID := caddytlsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/.SupportedCurvesscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddytls`/SupportedCurves.[curveName] |
| 796 | if _, ok := curvesAdded[curveID]; !ok { |
| 797 | curvesAdded[curveID] = struct{}{} |
| 798 | cfg.CurvePreferencesscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Config#CurvePreferences. = append(cfg.CurvePreferencesscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Config#CurvePreferences., curveID) |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | // only return a config if it's not empty |
| 803 | if reflectscip-go gomod github.com/golang/go/src go1.25.1 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.25.1 reflect/DeepEqual().(cfg, new(tlsscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/.Configscip-go gomod github.com/golang/go/src go1.25.1 `crypto/tls`/Config#)) { |
| 804 | return nil, nil |
| 805 | } |
| 806 | |
| 807 | return cfg, nil |
| 808 | } |
| 809 | |
| 810 | // KeepAlive holds configuration pertaining to HTTP Keep-Alive. |
| 811 | type KeepAlivescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive# struct { |
| 812 | // Whether HTTP Keep-Alive is enabled. Default: `true` |
| 813 | Enabledscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive#Enabled. *bool `json:"enabled,omitempty"` |
| 814 | |
| 815 | // How often to probe for liveness. Default: `30s`. |
| 816 | ProbeIntervalscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive#ProbeInterval. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Durationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Duration# `json:"probe_interval,omitempty"` |
| 817 | |
| 818 | // Maximum number of idle connections. Default: `0`, which means no limit. |
| 819 | MaxIdleConnsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive#MaxIdleConns. int `json:"max_idle_conns,omitempty"` |
| 820 | |
| 821 | // Maximum number of idle connections per host. Default: `32`. |
| 822 | MaxIdleConnsPerHostscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive#MaxIdleConnsPerHost. int `json:"max_idle_conns_per_host,omitempty"` |
| 823 | |
| 824 | // How long connections should be kept alive when idle. Default: `2m`. |
| 825 | IdleConnTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/KeepAlive#IdleConnTimeout. caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Durationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Duration# `json:"idle_timeout,omitempty"` |
| 826 | } |
| 827 | |
| 828 | // tcpRWTimeoutConn enforces read/write timeouts for a TCP connection. |
| 829 | // If it fails to set deadlines, the error is logged but does not abort |
| 830 | // the read/write attempt (ignoring the error is consistent with what |
| 831 | // the standard library does: https://github.com/golang/go/blob/c5da4fb7ac5cb7434b41fc9a1df3bee66c7f1a4d/src/net/http/server.go#L981-L986) |
| 832 | type tcpRWTimeoutConnscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn# struct { |
| 833 | *netscip-go gomod github.com/golang/go/src go1.25.1 net/.TCPConnscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#TCPConn. |
| 834 | readTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#readTimeout., writeTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#writeTimeout. timescip-go gomod github.com/golang/go/src go1.25.1 time/.Durationscip-go gomod github.com/golang/go/src go1.25.1 time/Duration# |
| 835 | loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#logger. *zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Loggerscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger# |
| 836 | } |
| 837 | |
| 838 | func (c *tcpRWTimeoutConnscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#) Readscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#Read().(b []byte) (int, error) { |
| 839 | if c.readTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#readTimeout. > 0 { |
| 840 | err := c.TCPConnscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#TCPConn..SetReadDeadlinescip-go gomod github.com/golang/go/src go1.25.1 net/conn#SetReadDeadline().(timescip-go gomod github.com/golang/go/src go1.25.1 time/.Nowscip-go gomod github.com/golang/go/src go1.25.1 time/Now().().Addscip-go gomod github.com/golang/go/src go1.25.1 time/Time#Add().(c.readTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#readTimeout.)) |
| 841 | if err != nil { |
| 842 | if ce := c.loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#logger..Checkscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Check().(zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/.ErrorLevelscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/ErrorLevel., "failed to set read deadline"); ce != nil { |
| 843 | ce.Writescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/CheckedEntry#Write().(zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Errorscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Error().(err)) |
| 844 | } |
| 845 | } |
| 846 | } |
| 847 | return c.TCPConnscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#TCPConn..Readscip-go gomod github.com/golang/go/src go1.25.1 net/conn#Read().(b) |
| 848 | } |
| 849 | |
| 850 | func (c *tcpRWTimeoutConnscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#) Writescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#Write().(b []byte) (int, error) { |
| 851 | if c.writeTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#writeTimeout. > 0 { |
| 852 | err := c.TCPConnscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#TCPConn..SetWriteDeadlinescip-go gomod github.com/golang/go/src go1.25.1 net/conn#SetWriteDeadline().(timescip-go gomod github.com/golang/go/src go1.25.1 time/.Nowscip-go gomod github.com/golang/go/src go1.25.1 time/Now().().Addscip-go gomod github.com/golang/go/src go1.25.1 time/Time#Add().(c.writeTimeoutscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#writeTimeout.)) |
| 853 | if err != nil { |
| 854 | if ce := c.loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#logger..Checkscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Logger#Check().(zapcorescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/.ErrorLevelscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/ErrorLevel., "failed to set write deadline"); ce != nil { |
| 855 | ce.Writescip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap/zapcore`/CheckedEntry#Write().(zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.Errorscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/Error().(err)) |
| 856 | } |
| 857 | } |
| 858 | } |
| 859 | return c.TCPConnscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/tcpRWTimeoutConn#TCPConn..Writescip-go gomod github.com/golang/go/src go1.25.1 net/conn#Write().(b) |
| 860 | } |
| 861 | |
| 862 | // decodeBase64DERCert base64-decodes, then DER-decodes, certStr. |
| 863 | func decodeBase64DERCertscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/decodeBase64DERCert().(certStr string) (*x509scip-go gomod github.com/golang/go/src go1.25.1 `crypto/x509`/.Certificatescip-go gomod github.com/golang/go/src go1.25.1 `crypto/x509`/Certificate#, error) { |
| 864 | // decode base64 |
| 865 | derBytes, err := base64scip-go gomod github.com/golang/go/src go1.25.1 `encoding/base64`/.StdEncodingscip-go gomod github.com/golang/go/src go1.25.1 `encoding/base64`/StdEncoding..DecodeStringscip-go gomod github.com/golang/go/src go1.25.1 `encoding/base64`/Encoding#DecodeString().(certStr) |
| 866 | if err != nil { |
| 867 | return nil, err |
| 868 | } |
| 869 | |
| 870 | // parse the DER-encoded certificate |
| 871 | return x509scip-go gomod github.com/golang/go/src go1.25.1 `crypto/x509`/.ParseCertificatescip-go gomod github.com/golang/go/src go1.25.1 `crypto/x509`/ParseCertificate().(derBytes) |
| 872 | } |
| 873 | |
| 874 | // Interface guards |
| 875 | var ( |
| 876 | _ caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Provisionerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Provisioner# = (*HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#)(nil) |
| 877 | _ httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.RoundTripperscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/RoundTripper# = (*HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#)(nil) |
| 878 | _ caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.CleanerUpperscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/CleanerUpper# = (*HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#)(nil) |
| 879 | _ TLSTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/TLSTransport# = (*HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#)(nil) |
| 880 | _ H2CTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/H2CTransport# = (*HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#)(nil) |
| 881 | _ HealthCheckSchemeOverriderTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HealthCheckSchemeOverriderTransport# = (*HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#)(nil) |
| 882 | _ ProxyProtocolTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/ProxyProtocolTransport# = (*HTTPTransportscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy`/HTTPTransport#)(nil) |
| 883 | ) |