mirror of https://github.com/v2ray/v2ray-core
				
				
				
			unfinished http proxy
							parent
							
								
									f0c1695db4
								
							
						
					
					
						commit
						05caf04eee
					
				| 
						 | 
					@ -0,0 +1,4 @@
 | 
				
			||||||
 | 
					package http
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Config interface {
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -2,36 +2,53 @@ package http
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"net"
 | 
						"net"
 | 
				
			||||||
	// "net/http"
 | 
						"net/http"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/v2ray/v2ray-core/app"
 | 
						"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"
 | 
						v2net "github.com/v2ray/v2ray-core/common/net"
 | 
				
			||||||
	jsonconfig "github.com/v2ray/v2ray-core/proxy/http/config/json"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type HttpProxyServer struct {
 | 
					type HttpProxyServer struct {
 | 
				
			||||||
	accepting  bool
 | 
						accepting  bool
 | 
				
			||||||
	dispatcher app.PacketDispatcher
 | 
						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{
 | 
						return &HttpProxyServer{
 | 
				
			||||||
		dispatcher: dispatcher,
 | 
							dispatcher: dispatcher,
 | 
				
			||||||
		config:     config,
 | 
							config:     config,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (server *HttpProxyServer) Listen(port v2net.Port) error {
 | 
					func (this *HttpProxyServer) Listen(port v2net.Port) error {
 | 
				
			||||||
	_, err := net.ListenTCP("tcp", &net.TCPAddr{
 | 
						server := http.Server{
 | 
				
			||||||
		IP:   []byte{0, 0, 0, 0},
 | 
							Addr:    ":" + port.String(),
 | 
				
			||||||
		Port: int(port),
 | 
							Handler: this,
 | 
				
			||||||
		Zone: "",
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		log.Error("HTTP Proxy failed to listen on port %d: %v", port, err)
 | 
					 | 
				
			||||||
		return err
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	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) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue