mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-11-28 12:30:13 +00:00
Compare commits
1
Commits
main
...
httpupgrade
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a47ea87d1a |
@@ -1,17 +1,35 @@
|
||||
package httpupgrade
|
||||
|
||||
import "net"
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/xtls/xray-core/transport/internet/stat"
|
||||
)
|
||||
|
||||
type connection struct {
|
||||
net.Conn
|
||||
remoteAddr net.Addr
|
||||
remainData []byte
|
||||
}
|
||||
|
||||
func newConnection(conn net.Conn, remoteAddr net.Addr) *connection {
|
||||
return &connection{
|
||||
func newConnection(conn net.Conn, remoteAddr net.Addr, remainData []byte) stat.Connection {
|
||||
return stat.Connection(&connection{
|
||||
Conn: conn,
|
||||
remoteAddr: remoteAddr,
|
||||
remainData: remainData,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *connection) Read(p []byte) (int, error) {
|
||||
if len(c.remainData) > 0 {
|
||||
n := copy(p, c.remainData)
|
||||
c.remainData = c.remainData[n:]
|
||||
if len(c.remainData) == 0 {
|
||||
c.remainData = nil
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
return c.Conn.Read(p)
|
||||
}
|
||||
|
||||
func (c *connection) RemoteAddr() net.Addr {
|
||||
|
||||
@@ -100,7 +100,12 @@ func (s *server) upgrade(conn net.Conn) (stat.Connection, error) {
|
||||
}
|
||||
remoteAddr = http_proto.ApplyTrustedXForwardedFor(req.Header, trustedXFF, remoteAddr)
|
||||
|
||||
return stat.Connection(newConnection(conn, remoteAddr)), nil
|
||||
var remainData []byte
|
||||
if remainLength := connReader.Buffered(); remainLength > 0 {
|
||||
remainData = make([]byte, remainLength)
|
||||
connReader.Read(remainData)
|
||||
}
|
||||
return newConnection(conn, remoteAddr, remainData), nil
|
||||
}
|
||||
|
||||
func (s *server) keepAccepting() {
|
||||
|
||||
Reference in New Issue
Block a user