mirror of
https://github.com/ehang-io/nps.git
synced 2025-07-02 04:00:42 +00:00
read full http proxy request, fix UnexpectedEOF error
This commit is contained in:
parent
196c08cb32
commit
e2d249a576
@ -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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user