mirror of
https://github.com/fatedier/frp.git
synced 2025-07-27 07:35:07 +00:00
update github.com/pires/go-proxyproto to v0.5.0
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/fatedier/frp/test/e2e/pkg/rpc"
|
||||
libnet "github.com/fatedier/golib/net"
|
||||
)
|
||||
|
||||
@@ -210,15 +211,14 @@ func sendHTTPRequest(method, urlstr string, host string, headers map[string]stri
|
||||
}
|
||||
|
||||
func sendRequestByConn(c net.Conn, content []byte) ([]byte, error) {
|
||||
_, err := c.Write(content)
|
||||
_, err := rpc.WriteBytes(c, content)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("write error: %v", err)
|
||||
}
|
||||
|
||||
buf := make([]byte, 2048)
|
||||
n, err := c.Read(buf)
|
||||
buf, err := rpc.ReadBytes(c)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read error: %v", err)
|
||||
}
|
||||
return buf[:n], nil
|
||||
return buf, nil
|
||||
}
|
||||
|
35
test/e2e/pkg/rpc/rpc.go
Normal file
35
test/e2e/pkg/rpc/rpc.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"io"
|
||||
)
|
||||
|
||||
func WriteBytes(w io.Writer, buf []byte) (int, error) {
|
||||
out := bytes.NewBuffer(nil)
|
||||
binary.Write(out, binary.BigEndian, int64(len(buf)))
|
||||
out.Write(buf)
|
||||
return w.Write(out.Bytes())
|
||||
}
|
||||
|
||||
func ReadBytes(r io.Reader) ([]byte, error) {
|
||||
// To compatible with UDP connection, use bufio reader here to avoid lost conent.
|
||||
rd := bufio.NewReader(r)
|
||||
|
||||
var length int64
|
||||
if err := binary.Read(rd, binary.BigEndian, &length); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
buffer := make([]byte, length)
|
||||
n, err := io.ReadFull(rd, buffer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if int64(n) != length {
|
||||
return nil, errors.New("invalid length")
|
||||
}
|
||||
return buffer, nil
|
||||
}
|
Reference in New Issue
Block a user