http.go 842 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package http
  2. import (
  3. "net"
  4. // "net/http"
  5. "github.com/v2ray/v2ray-core/app"
  6. "github.com/v2ray/v2ray-core/common/log"
  7. v2net "github.com/v2ray/v2ray-core/common/net"
  8. jsonconfig "github.com/v2ray/v2ray-core/proxy/http/config/json"
  9. )
  10. type HttpProxyServer struct {
  11. accepting bool
  12. dispatcher app.PacketDispatcher
  13. config *jsonconfig.HttpProxyConfig
  14. }
  15. func NewHttpProxyServer(dispatcher app.PacketDispatcher, config *jsonconfig.HttpProxyConfig) *HttpProxyServer {
  16. return &HttpProxyServer{
  17. dispatcher: dispatcher,
  18. config: config,
  19. }
  20. }
  21. func (server *HttpProxyServer) Listen(port v2net.Port) error {
  22. _, err := net.ListenTCP("tcp", &net.TCPAddr{
  23. IP: []byte{0, 0, 0, 0},
  24. Port: int(port),
  25. Zone: "",
  26. })
  27. if err != nil {
  28. log.Error("HTTP Proxy failed to listen on port %d: %v", port, err)
  29. return err
  30. }
  31. return nil
  32. }