Skip to content

Commit

Permalink
add documentation for error returned by ParseRequest, use it in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Nov 12, 2024
1 parent 892f6e9 commit dd9d274
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions integration/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package main
import (
"context"
"crypto/tls"
"errors"
"fmt"
"log"
"net"
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit dd9d274

Please sign in to comment.