diff --git a/integration/proxy/proxy.go b/integration/proxy/proxy.go index 542c7c8..1406dc9 100644 --- a/integration/proxy/proxy.go +++ b/integration/proxy/proxy.go @@ -5,6 +5,7 @@ package main import ( "context" "crypto/tls" + "errors" "fmt" "log" "net" @@ -175,6 +176,11 @@ func run(bindTo netip.AddrPort, remoteAddr netip.Addr, route netip.Prefix, ipPro mux.HandleFunc("/vpn", func(w http.ResponseWriter, r *http.Request) { req, err := connectip.ParseRequest(r, template) if err != nil { + var perr *connectip.RequestParseError + if errors.As(err, &perr) { + w.WriteHeader(perr.HTTPStatus) + return + } w.WriteHeader(http.StatusBadRequest) return } diff --git a/request.go b/request.go index e99c7ba..0fd7ae5 100644 --- a/request.go +++ b/request.go @@ -40,6 +40,8 @@ type RequestParseError struct { func (e *RequestParseError) Error() string { return e.Err.Error() } func (e *RequestParseError) Unwrap() error { return e.Err } +// ParseRequest parses a CONNECT-IP request. +// The template is the URI template that clients will use to configure this proxy. func ParseRequest(r *http.Request, template *uritemplate.Template) (*Request, error) { if len(template.Varnames()) > 0 { return nil, errors.New("connect-ip-go currently does not support IP flow forwarding")