use textproto to read http headers

master
fangdingjun 8 years ago
parent c2c1be3ac3
commit db1424cbd4

@ -7,6 +7,7 @@ import (
"github.com/fangdingjun/obfssh" "github.com/fangdingjun/obfssh"
socks "github.com/fangdingjun/socks-go" socks "github.com/fangdingjun/socks-go"
"net" "net"
"net/textproto"
"net/url" "net/url"
"os" "os"
"strconv" "strconv"
@ -54,8 +55,9 @@ func httpProxyHandshake(c net.Conn, host string, port int) error {
r := bufio.NewReader(c) r := bufio.NewReader(c)
tp := textproto.NewReader(r)
// read status line // read status line
statusLine, err := r.ReadString('\n') statusLine, err := tp.ReadLine()
if err != nil { if err != nil {
return err return err
} }
@ -66,7 +68,7 @@ func httpProxyHandshake(c net.Conn, host string, port int) error {
status := strings.Fields(statusLine)[1] status := strings.Fields(statusLine)[1]
statusCode, err := strconv.ParseInt(status, 10, 32) statusCode, err := strconv.Atoi(status)
if err != nil { if err != nil {
return err return err
} }
@ -76,16 +78,9 @@ func httpProxyHandshake(c net.Conn, host string, port int) error {
} }
// read header // read header
for { if _, err = tp.ReadMIMEHeader(); err != nil {
h, err := r.ReadString('\n')
if err != nil {
return err return err
} }
h1 := strings.Trim(h, " \r\n")
if h1 == "" {
break
}
}
return nil return nil
} }

Loading…
Cancel
Save