http.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package http
  2. import (
  3. "net"
  4. "net/http"
  5. "strings"
  6. "github.com/v2ray/v2ray-core/app"
  7. _ "github.com/v2ray/v2ray-core/common/log"
  8. v2net "github.com/v2ray/v2ray-core/common/net"
  9. )
  10. type HttpProxyServer struct {
  11. accepting bool
  12. dispatcher app.PacketDispatcher
  13. config Config
  14. }
  15. func NewHttpProxyServer(dispatcher app.PacketDispatcher, config Config) *HttpProxyServer {
  16. return &HttpProxyServer{
  17. dispatcher: dispatcher,
  18. config: config,
  19. }
  20. }
  21. func (this *HttpProxyServer) Listen(port v2net.Port) error {
  22. server := http.Server{
  23. Addr: ":" + port.String(),
  24. Handler: this,
  25. }
  26. return server.ListenAndServe()
  27. }
  28. func (this *HttpProxyServer) ServeHTTP(w http.ResponseWriter, request *http.Request) {
  29. if strings.ToUpper(request.Method) == "CONNECT" {
  30. host, port, err := net.SplitHostPort(request.URL.Host)
  31. if err != nil {
  32. if strings.Contains(err.(*net.AddrError).Err, "missing port") {
  33. host = request.URL.Host
  34. port = "80"
  35. } else {
  36. http.Error(w, "Bad Request", 400)
  37. return
  38. }
  39. }
  40. _ = host + port
  41. } else {
  42. }
  43. }
  44. func (this *HttpProxyServer) handleConnect(response http.ResponseWriter, request *http.Request) {
  45. }