Skip to content

Commit

Permalink
read full http proxy request, fix UnexpectedEOF error
Browse files Browse the repository at this point in the history
  • Loading branch information
ffdfgdfg committed Feb 10, 2020
1 parent 196c08c commit e2d249a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/conn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,30 @@ func NewConn(conn net.Conn) *Conn {
return &Conn{Conn: conn}
}

func (s *Conn) readRequest(buf []byte) (n int, err error) {
var rd int
for {
rd, err = s.Read(buf[n:])
if err != nil {
return
}
n += rd
if string(buf[n-4:n]) == "\r\n\r\n" {
return
}
// buf is full, can't contain the request
if n == cap(buf) {
err = io.ErrUnexpectedEOF
return
}
}
}

//get host 、connection type、method...from connection
func (s *Conn) GetHost() (method, address string, rb []byte, err error, r *http.Request) {
var b [32 * 1024]byte
var n int
if n, err = s.Read(b[:]); err != nil {
if n, err = s.readRequest(b[:]); err != nil {
return
}
rb = b[:n]
Expand Down

0 comments on commit e2d249a

Please sign in to comment.