summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/reverseproxy/httptransport.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-09-03 16:56:09 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-09-03 16:56:09 -0600
commit652460e03e11a037d9f86b09b3546c9e42733d2d (patch)
tree9b1042f3fc880f87ca25949618fea45e6960080a /modules/caddyhttp/reverseproxy/httptransport.go
parent4a1e1649bc985e9658d326ed433a101d7d79ae30 (diff)
Some cleanup and godoc
Diffstat (limited to 'modules/caddyhttp/reverseproxy/httptransport.go')
-rw-r--r--modules/caddyhttp/reverseproxy/httptransport.go21
1 files changed, 9 insertions, 12 deletions
diff --git a/modules/caddyhttp/reverseproxy/httptransport.go b/modules/caddyhttp/reverseproxy/httptransport.go
index 999a352..d9dc457 100644
--- a/modules/caddyhttp/reverseproxy/httptransport.go
+++ b/modules/caddyhttp/reverseproxy/httptransport.go
@@ -31,14 +31,13 @@ func init() {
caddy.RegisterModule(HTTPTransport{})
}
-// TODO: This is the default transport, basically just http.Transport, but we define JSON struct tags...
+// HTTPTransport is essentially a configuration wrapper for http.Transport.
+// It defines a JSON structure useful when configuring the HTTP transport
+// for Caddy's reverse proxy.
type HTTPTransport struct {
- // TODO: Actually this is where the TLS config should go, technically...
- // as well as keepalives and dial timeouts...
// TODO: It's possible that other transports (like fastcgi) might be
// able to borrow/use at least some of these config fields; if so,
// move them into a type called CommonTransport and embed it
-
TLS *TLSConfig `json:"tls,omitempty"`
KeepAlive *KeepAlive `json:"keep_alive,omitempty"`
Compression *bool `json:"compression,omitempty"`
@@ -50,7 +49,6 @@ type HTTPTransport struct {
MaxResponseHeaderSize int64 `json:"max_response_header_size,omitempty"`
WriteBufferSize int `json:"write_buffer_size,omitempty"`
ReadBufferSize int `json:"read_buffer_size,omitempty"`
- // TODO: ProxyConnectHeader?
RoundTripper http.RoundTripper `json:"-"`
}
@@ -63,6 +61,8 @@ func (HTTPTransport) CaddyModule() caddy.ModuleInfo {
}
}
+// Provision sets up h.RoundTripper with a http.Transport
+// that is ready to use.
func (h *HTTPTransport) Provision(ctx caddy.Context) error {
dialer := &net.Dialer{
Timeout: time.Duration(h.DialTimeout),
@@ -109,16 +109,13 @@ func (h *HTTPTransport) Provision(ctx caddy.Context) error {
return nil
}
+// RoundTrip implements http.RoundTripper with h.RoundTripper.
func (h HTTPTransport) RoundTrip(req *http.Request) (*http.Response, error) {
return h.RoundTripper.RoundTrip(req)
}
-func defaultTLSConfig() *tls.Config {
- return &tls.Config{
- NextProtos: []string{"h2", "http/1.1"}, // TODO: ensure this makes HTTP/2 work
- }
-}
-
+// TLSConfig holds configuration related to the
+// TLS configuration for the transport/client.
type TLSConfig struct {
RootCAPool []string `json:"root_ca_pool,omitempty"`
// TODO: Should the client cert+key config use caddytls.CertificateLoader modules?
@@ -186,6 +183,7 @@ func decodeBase64DERCert(certStr string) (*x509.Certificate, error) {
return x509.ParseCertificate(derBytes)
}
+// KeepAlive holds configuration pertaining to HTTP Keep-Alive.
type KeepAlive struct {
Enabled *bool `json:"enabled,omitempty"`
ProbeInterval caddy.Duration `json:"probe_interval,omitempty"`
@@ -200,7 +198,6 @@ var (
KeepAlive: 30 * time.Second,
}
- // TODO: does this need to be configured to enable HTTP/2?
defaultTransport = &http.Transport{
DialContext: defaultDialer.DialContext,
TLSHandshakeTimeout: 5 * time.Second,