Skip to content

Commit 9fde1f5

Browse files
committed
fix: tls in HTTP1 after protocol detect
1 parent e55b309 commit 9fde1f5

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

http/http.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"compress/gzip"
77
"context"
88
"crypto/rand"
9+
"crypto/tls"
910
"encoding/hex"
1011
"fmt"
1112
"io"
@@ -153,6 +154,21 @@ func newReqID() string {
153154
return hex.EncodeToString(b)
154155
}
155156

157+
func (h *Midware) preparetls(rw http.ResponseWriter, r *http.Request, conn *tcp.Conn) {
158+
if r.TLS == nil {
159+
head := conn.Head()
160+
if head > 1 {
161+
if conn.Protocol()[head-1] == "TLS" {
162+
if conn, ok := conn.TopConn().(*utils.RwConn); ok {
163+
r.TLS = new(tls.ConnectionState)
164+
*r.TLS = conn.Rawconn.(*tls.Conn).ConnectionState()
165+
}
166+
}
167+
}
168+
}
169+
170+
}
171+
156172
func (h *Midware) head(rw http.ResponseWriter, r *http.Request, conn *tcp.Conn) {
157173
ngrw := &NgResponseWriter{
158174
writer: nil,

http/midware.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func (h *Midware) Handle(c *tcp.Conn) tcp.SerRet {
9191
switch top {
9292
case "HTTP1":
9393
http.Serve(utils.ConnGetSocket(c.TopConn()), http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
94+
h.preparetls(rw, r, c)
9495
h.head(rw, r, c)
9596
}))
9697
return tcp.Close

tcp/connection.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,17 @@ func (c *Conn) TopConn() net.Conn {
5454
return c.conn[c.head]
5555
}
5656
func (c *Conn) TopProtocol() string {
57-
c.mu.RLock()
58-
defer c.mu.RUnlock()
5957
return c.proto[c.head]
6058
}
59+
60+
func (c *Conn) Protocol() []string {
61+
return c.proto
62+
}
63+
64+
func (c *Conn) Head() int {
65+
return int(c.head)
66+
}
67+
6168
func (c *Conn) unsync_genProtocols() {
6269
c.protos = ""
6370
for _, v := range c.proto {

0 commit comments

Comments
 (0)