Skip to content

Commit

Permalink
optimize missing "Host" header response
Browse files Browse the repository at this point in the history
  • Loading branch information
bddjr committed Dec 11, 2024
1 parent 32d7343 commit 5149f3c
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,14 @@ func (c *conn) Read(b []byte) (int, error) {
c.log("hlfhr: Read request error from ", c.Conn.RemoteAddr(), ": ", err)
return 0, ErrHttpOnHttpsPort
}
if r.Host == "" {
const err = "missing required Host header"
io.WriteString(c.Conn, "HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n"+err)
c.log("hlfhr: Read request error from ", c.Conn.RemoteAddr(), ": "+err)
return 0, ErrHttpOnHttpsPort
}

// Response
w := NewResponse()
if c.srv.HttpOnHttpsPortErrorHandler != nil {
if r.Host == "" {
// missing "Host" header
w.WriteHeader(400)
w.WriteString("missing required Host header")
} else if c.srv.HttpOnHttpsPortErrorHandler != nil {
// Handler
c.srv.HttpOnHttpsPortErrorHandler.ServeHTTP(w, r)
} else {
Expand Down

0 comments on commit 5149f3c

Please sign in to comment.