Files
proxy/server/fwd/http/http.go

63 lines
1.2 KiB
Go

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