mirror of
https://github.com/fosrl/newt.git
synced 2026-05-12 03:09:56 +00:00
Merge pull request #345 from LaurenceJJones/investigate/https-permanent-redirect-loop
fix(http): populate Request.TLS for private HTTPS via httpConnCtx
This commit is contained in:
@@ -139,6 +139,21 @@ type httpConnCtx struct {
|
||||
rule *SubnetRule
|
||||
}
|
||||
|
||||
// ConnectionState allows net/http.Server to populate Request.TLS when the
|
||||
// underlying connection is TLS (e.g. *tls.Conn from tls.Server). Without this,
|
||||
// the connection is not *tls.Conn and does not expose ConnectionState through
|
||||
// the net.Conn interface field, so tlsState stays nil and the HTTPS redirect
|
||||
// in handleRequest runs on every request.
|
||||
func (c *httpConnCtx) ConnectionState() tls.ConnectionState {
|
||||
type tlsConn interface {
|
||||
ConnectionState() tls.ConnectionState
|
||||
}
|
||||
if tc, ok := c.Conn.(tlsConn); ok {
|
||||
return tc.ConnectionState()
|
||||
}
|
||||
return tls.ConnectionState{}
|
||||
}
|
||||
|
||||
// connCtxKey is the unexported context key used to store a *SubnetRule on the
|
||||
// per-connection context created by http.Server.ConnContext.
|
||||
type connCtxKey struct{}
|
||||
|
||||
Reference in New Issue
Block a user