Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add documentation for error returned by ParseRequest, use it in tests #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading