Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bddjr committed Dec 9, 2024
1 parent dcf5da9 commit 6a45702
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var ErrHttpOnHttpsPort = errors.New("client sent an HTTP request to an HTTPS ser

type conn struct {
net.Conn
tc *tls.Conn
tc *tls.Conn // reading tls if nil
srv *Server
}

Expand Down Expand Up @@ -52,14 +52,15 @@ func (c *conn) readRequest(b []byte, n int) (*http.Request, error) {

func (c *conn) Read(b []byte) (int, error) {
n, err := c.Conn.Read(b)
if err != nil || n <= 0 {
if c.tc == nil || err != nil || n <= 0 {
return n, err
}

if !ConnFirstByteLooksLikeHttp(b[0]) {
// Not looks like HTTP.
// TLS handshake: 0x16
c.setRawConn()
c.tc = nil
return n, nil
}

Expand Down

0 comments on commit 6a45702

Please sign in to comment.