From 05caf04eee45452c0986af63d0320342268f74c5 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Mon, 14 Dec 2015 16:26:29 +0000 Subject: [PATCH] unfinished http proxy --- proxy/http/config.go | 4 +++ proxy/http/http.go | 47 +++++++++++++++++++--------- proxy/http/{config => }/json/json.go | 0 3 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 proxy/http/config.go rename proxy/http/{config => }/json/json.go (100%) diff --git a/proxy/http/config.go b/proxy/http/config.go new file mode 100644 index 00000000..1a20700f --- /dev/null +++ b/proxy/http/config.go @@ -0,0 +1,4 @@ +package http + +type Config interface { +} diff --git a/proxy/http/http.go b/proxy/http/http.go index e527846b..1ebf7600 100644 --- a/proxy/http/http.go +++ b/proxy/http/http.go @@ -2,36 +2,53 @@ package http import ( "net" - // "net/http" + "net/http" + "strings" "github.com/v2ray/v2ray-core/app" - "github.com/v2ray/v2ray-core/common/log" + _ "github.com/v2ray/v2ray-core/common/log" v2net "github.com/v2ray/v2ray-core/common/net" - jsonconfig "github.com/v2ray/v2ray-core/proxy/http/config/json" ) type HttpProxyServer struct { accepting bool dispatcher app.PacketDispatcher - config *jsonconfig.HttpProxyConfig + config Config } -func NewHttpProxyServer(dispatcher app.PacketDispatcher, config *jsonconfig.HttpProxyConfig) *HttpProxyServer { +func NewHttpProxyServer(dispatcher app.PacketDispatcher, config Config) *HttpProxyServer { return &HttpProxyServer{ dispatcher: dispatcher, config: config, } } -func (server *HttpProxyServer) Listen(port v2net.Port) error { - _, err := net.ListenTCP("tcp", &net.TCPAddr{ - IP: []byte{0, 0, 0, 0}, - Port: int(port), - Zone: "", - }) - if err != nil { - log.Error("HTTP Proxy failed to listen on port %d: %v", port, err) - return err +func (this *HttpProxyServer) Listen(port v2net.Port) error { + server := http.Server{ + Addr: ":" + port.String(), + Handler: this, } - return nil + return server.ListenAndServe() +} + +func (this *HttpProxyServer) ServeHTTP(w http.ResponseWriter, request *http.Request) { + if strings.ToUpper(request.Method) == "CONNECT" { + host, port, err := net.SplitHostPort(request.URL.Host) + if err != nil { + if strings.Contains(err.(*net.AddrError).Err, "missing port") { + host = request.URL.Host + port = "80" + } else { + http.Error(w, "Bad Request", 400) + return + } + } + _ = host + port + } else { + + } +} + +func (this *HttpProxyServer) handleConnect(response http.ResponseWriter, request *http.Request) { + } diff --git a/proxy/http/config/json/json.go b/proxy/http/json/json.go similarity index 100% rename from proxy/http/config/json/json.go rename to proxy/http/json/json.go