mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-21 16:56:27 -05:00
ssr compatibility
This commit is contained in:
parent
d2263a452d
commit
f108633e2e
@ -15,6 +15,26 @@ const (
|
||||
ENDING = CRLF + CRLF
|
||||
)
|
||||
|
||||
type Reader interface {
|
||||
Read(io.Reader) (*alloc.Buffer, error)
|
||||
}
|
||||
|
||||
type Writer interface {
|
||||
Write(io.Writer) error
|
||||
}
|
||||
|
||||
type NoOpReader struct{}
|
||||
|
||||
func (this *NoOpReader) Read(io.Reader) (*alloc.Buffer, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
type NoOpWriter struct{}
|
||||
|
||||
func (this *NoOpWriter) Write(io.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type HeaderReader struct {
|
||||
}
|
||||
|
||||
@ -34,6 +54,10 @@ func (*HeaderReader) Read(reader io.Reader) (*alloc.Buffer, error) {
|
||||
buffer.Slice(0, len(ENDING))
|
||||
}
|
||||
}
|
||||
if buffer.IsEmpty() {
|
||||
buffer.Release()
|
||||
return nil, nil
|
||||
}
|
||||
return buffer, nil
|
||||
}
|
||||
|
||||
@ -61,11 +85,11 @@ type HttpConn struct {
|
||||
net.Conn
|
||||
|
||||
readBuffer *alloc.Buffer
|
||||
oneTimeReader *HeaderReader
|
||||
oneTimeWriter *HeaderWriter
|
||||
oneTimeReader Reader
|
||||
oneTimeWriter Writer
|
||||
}
|
||||
|
||||
func NewHttpConn(conn net.Conn, reader *HeaderReader, writer *HeaderWriter) *HttpConn {
|
||||
func NewHttpConn(conn net.Conn, reader Reader, writer Writer) *HttpConn {
|
||||
return &HttpConn{
|
||||
Conn: conn,
|
||||
oneTimeReader: reader,
|
||||
@ -145,7 +169,16 @@ func (this HttpAuthenticator) Client(conn net.Conn) net.Conn {
|
||||
if this.config.Request == nil && this.config.Response == nil {
|
||||
return conn
|
||||
}
|
||||
return NewHttpConn(conn, new(HeaderReader), this.GetClientWriter())
|
||||
var reader Reader = new(NoOpReader)
|
||||
if this.config.Request != nil {
|
||||
reader = new(HeaderReader)
|
||||
}
|
||||
|
||||
var writer Writer = new(NoOpWriter)
|
||||
if this.config.Response != nil {
|
||||
writer = this.GetClientWriter()
|
||||
}
|
||||
return NewHttpConn(conn, reader, writer)
|
||||
}
|
||||
|
||||
func (this HttpAuthenticator) Server(conn net.Conn) net.Conn {
|
||||
|
Loading…
Reference in New Issue
Block a user