aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/server.go
diff options
context:
space:
mode:
authorWeidi Deng <weidi_deng@icloud.com>2022-11-02 01:19:16 +0000
committerGopher Robot <gobot@golang.org>2025-04-16 07:05:57 -0700
commit5413abc44025f281f2a7ea37b3e0043591dbed3e (patch)
treecf73ac54aa5b6b66b459efdebb61d3a3d8ed4525 /src/net/http/server.go
parent786e62bcd3f03d73ddf0c999780ffe6f1a0319ea (diff)
downloadgo-5413abc44025f281f2a7ea37b3e0043591dbed3e.tar.xz
net/http: set Request.TLS when net.Conn implements ConnectionState
Fixes #56104 Change-Id: I8fbbb00379e51323e2782144070cbcad650eb6f1 GitHub-Last-Rev: 62d7a8064e4f2173f0d8e02ed91a7e8de7f13fca GitHub-Pull-Request: golang/go#56110 Reviewed-on: https://go-review.googlesource.com/c/go/+/440795 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Sean Liao <sean@liao.dev> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Diffstat (limited to 'src/net/http/server.go')
-rw-r--r--src/net/http/server.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/net/http/server.go b/src/net/http/server.go
index 49a9d30207..f2bedb7d6a 100644
--- a/src/net/http/server.go
+++ b/src/net/http/server.go
@@ -1924,6 +1924,10 @@ func isCommonNetReadError(err error) bool {
return false
}
+type connectionStater interface {
+ ConnectionState() tls.ConnectionState
+}
+
// Serve a new connection.
func (c *conn) serve(ctx context.Context) {
if ra := c.rwc.RemoteAddr(); ra != nil {
@@ -1996,6 +2000,14 @@ func (c *conn) serve(ctx context.Context) {
// HTTP/1.x from here on.
+ // Set Request.TLS if the conn is not a *tls.Conn, but implements ConnectionState.
+ if c.tlsState == nil {
+ if tc, ok := c.rwc.(connectionStater); ok {
+ c.tlsState = new(tls.ConnectionState)
+ *c.tlsState = tc.ConnectionState()
+ }
+ }
+
ctx, cancelCtx := context.WithCancel(ctx)
c.cancelCtx = cancelCtx
defer cancelCtx()