添加 HTTP 代理连接处理逻辑
This commit is contained in:
@@ -124,6 +124,8 @@ func (s *Server) acceptSocks(ls net.Listener) error {
|
|||||||
conn, err := socks.Process(s.ctx, conn)
|
conn, err := socks.Process(s.ctx, conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("处理 socks 连接失败", "err", err)
|
slog.Error("处理 socks 连接失败", "err", err)
|
||||||
|
utils.Close(conn)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case <-s.ctx.Done():
|
case <-s.ctx.Done():
|
||||||
|
|||||||
@@ -1 +1,62 @@
|
|||||||
package http
|
package http
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"context"
|
||||||
|
"net"
|
||||||
|
"net/textproto"
|
||||||
|
"proxy-server/server/fwd/core"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Request struct {
|
||||||
|
auth *core.AuthContext
|
||||||
|
dest *core.FwdAddr
|
||||||
|
}
|
||||||
|
|
||||||
|
func Process(ctx context.Context, conn net.Conn) (*core.Conn, error) {
|
||||||
|
reader := bufio.NewReader(conn)
|
||||||
|
textReader := textproto.NewReader(reader)
|
||||||
|
|
||||||
|
// 首行
|
||||||
|
line, err := textReader.ReadLine()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
parts := strings.Split(line, " ")
|
||||||
|
if len(parts) != 3 {
|
||||||
|
return nil, errors.New("invalid http request")
|
||||||
|
}
|
||||||
|
|
||||||
|
var req Request
|
||||||
|
if parts[0] == "CONNECT" {
|
||||||
|
req, err = processHttps(ctx, textReader)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
req, err = processHttp(ctx, textReader)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &core.Conn{
|
||||||
|
Conn: conn,
|
||||||
|
Reader: reader,
|
||||||
|
Tag: conn.RemoteAddr().String() + "_" + conn.LocalAddr().String(),
|
||||||
|
Protocol: "http",
|
||||||
|
Dest: req.dest,
|
||||||
|
Auth: req.auth,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func processHttps(ctx context.Context, reader *textproto.Reader) (Request, error) {
|
||||||
|
panic("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func processHttp(ctx context.Context, reader *textproto.Reader) (Request, error) {
|
||||||
|
panic("not implemented")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user