diff --git a/socks5.go b/socks5.go index 90005c2..0a633b3 100644 --- a/socks5.go +++ b/socks5.go @@ -48,17 +48,23 @@ func WriteUdpAddr(w io.Writer, addr Address) error { return err } } else if addr.Name != "" { - if len(addr.Name) > 255 { + l := len(addr.Name) + if l > 255 { return errors.New("errStringTooLong") } - con := make([]byte, 2+len(addr.Name)) + con := make([]byte, 2+l+2) con[0] = fqdnAddress - con[1] = byte(len(addr.Name)) + con[1] = byte(l) copy(con[2:], []byte(addr.Name)) + binary.BigEndian.PutUint16(con[2+l:], uint16(addr.Port)) _, err := w.Write(con) return err } else { - _, err := w.Write([]byte{ipv4Address, 0, 0, 0, 0}) + con := make([]byte, 1+4+2) + con[0] = ipv4Address + copy(con[1:], net.IPv4(0, 0, 0, 0)) + binary.BigEndian.PutUint16(con[1+4:], uint16(addr.Port)) + _, err := w.Write(con) return err } } diff --git a/test/protocol/http2_test.go b/test/protocol/http2_test.go index 823d948..48d9b1c 100644 --- a/test/protocol/http2_test.go +++ b/test/protocol/http2_test.go @@ -13,7 +13,7 @@ func TestHttp2(t *testing.T) { t.Error(err) } if resp.StatusCode() != 200 { - t.Error("resp.StatusCode!= 200") + t.Error("resp.StatusCode2!= 200") } if resp.Proto() != "HTTP/2.0" { t.Error("resp.Proto!= HTTP/2.0") @@ -28,4 +28,14 @@ func TestHttp2(t *testing.T) { if resp.Proto() != "HTTP/2.0" { t.Error("resp.Proto!= HTTP/2.0") } + resp, err = requests.Post(context.TODO(), "https://mp.weixin.qq.com", requests.RequestOption{Body: "fasfasfsdfdssdsfasdfasdfsadfsdf对方是大翻身大翻身大翻身对方的身份"}) + if err != nil { + t.Error(err) + } + if resp.StatusCode() != 200 { + t.Error("resp.StatusCode!= 200") + } + if resp.Proto() != "HTTP/2.0" { + t.Error("resp.Proto!= HTTP/2.0") + } }