This commit is contained in:
gospider
2025-02-07 08:32:20 +08:00
parent 50a8c48a30
commit 16401b0fa3
2 changed files with 21 additions and 5 deletions

View File

@@ -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
}
}

View File

@@ -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")
}
}