Skip to content

Commit

Permalink
fix: use transport for regular HTTP proxying (#79)
Browse files Browse the repository at this point in the history
* Fix HTTP proxy handler

* Clarify if
  • Loading branch information
fortuna authored Sep 28, 2023
1 parent 7127eed commit b950bdb
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions x/httpproxy/connect_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
package httpproxy

import (
"context"
"fmt"
"io"
"net"
"net/http"
"strings"

"github.com/Jigsaw-Code/outline-sdk/transport"
)
Expand All @@ -35,11 +38,12 @@ func (h *handler) ServeHTTP(proxyResp http.ResponseWriter, proxyReq *http.Reques
if proxyReq.Method == http.MethodConnect {
h.handleConnect(proxyResp, proxyReq)
return
} else if proxyReq.URL.Host != "" {
}
if proxyReq.URL.Host != "" {
h.handleHTTPProxyRequest(proxyResp, proxyReq)
} else {
http.Error(proxyResp, "Not Found", http.StatusNotFound)
return
}
http.Error(proxyResp, "Not Found", http.StatusNotFound)
}

func (h *handler) handleHTTPProxyRequest(proxyResp http.ResponseWriter, proxyReq *http.Request) {
Expand Down Expand Up @@ -124,5 +128,11 @@ func (h *handler) handleConnect(proxyResp http.ResponseWriter, proxyReq *http.Re
// The resulting handler is currently vulnerable to probing attacks. It's ok as a localhost proxy
// but it may be vulnerable if used as a public proxy.
func NewConnectHandler(dialer transport.StreamDialer) http.Handler {
return &handler{dialer, *http.DefaultClient}
dialContext := func(ctx context.Context, network, addr string) (net.Conn, error) {
if !strings.HasPrefix(network, "tcp") {
return nil, fmt.Errorf("protocol not supported: %v", network)
}
return dialer.Dial(ctx, addr)
}
return &handler{dialer, http.Client{Transport: &http.Transport{DialContext: dialContext}}}
}

0 comments on commit b950bdb

Please sign in to comment.