Skip to content

Commit

Permalink
Merge pull request #361 from simonmittag/log-fix
Browse files Browse the repository at this point in the history
Log fix
  • Loading branch information
simonmittag authored Dec 2, 2023
2 parents 3e24409 + fab215d commit de7916f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
36 changes: 26 additions & 10 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/google/uuid"
"github.com/lestrrat-go/jwx/jwa"
"github.com/lestrrat-go/jwx/jws"
"github.com/lestrrat-go/jwx/jwt"
"github.com/rs/zerolog"
"golang.org/x/net/idna"
"io"
"io/ioutil"
"net"
"net/http"
"strconv"
"strings"
"time"
unicode "unicode"

"github.com/google/uuid"
"github.com/lestrrat-go/jwx/jwa"
"github.com/lestrrat-go/jwx/jws"
"github.com/lestrrat-go/jwx/jwt"
"github.com/rs/zerolog"
"golang.org/x/net/idna"

"github.com/rs/zerolog/log"
)

Expand Down Expand Up @@ -523,11 +525,25 @@ func infoOrDebugEv(proxy *Proxy) *zerolog.Event {

const colon = ":"

func isIPv6(address string) bool {
ip := net.ParseIP(address)
return ip != nil && ip.To4() == nil
}

func parseHost(request *http.Request) string {
//ignore conversion errors
al := strings.Split(request.Host, colon)[0]
al2, _ := idna.ToASCII(al)
return al2
host := request.Host
hostElements := strings.Split(host, ":")
//trim port for ipv4
if len(hostElements) == 2 {
host = hostElements[0]
}

//trim port for ipv6
if strings.Contains(host, "]") {
host = host[:strings.LastIndex(host, "]")+1]
}
host, _ = idna.ToASCII(host)
return host
}

func parseMethod(request *http.Request) string {
Expand Down
13 changes: 13 additions & 0 deletions proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,19 @@ func TestParseHost(t *testing.T) {
host string
}{
{name: "simple", url: "http://host/path", host: "host"},
{name: "simple ipv4", url: "http://127.0.0.1/path", host: "127.0.0.1"},
{name: "ipv4 with port", url: "http://127.0.0.1:8080/path", host: "127.0.0.1"},
{name: "simple ipv6", url: "http://::1/path", host: "::1"},
{name: "simple ipv6 in brackets", url: "http://[::1]/path", host: "[::1]"},
{name: "simple ipv6 in brackets", url: "http://[::]/path", host: "[::]"},
{name: "simple ipv6 in brackets", url: "http://[2001:db8::]/path", host: "[2001:db8::]"},
{name: "simple ipv6 in brackets", url: "http://[::1234:5678]/path", host: "[::1234:5678]"},
{name: "simple ipv6 in brackets", url: "http://[2001:db8::1234:5678]/path", host: "[2001:db8::1234:5678]"},
{name: "full ipv6 in brackets", url: "http://[2001:db8:3333:4444:5555:6666:7777:8888]/path", host: "[2001:db8:3333:4444:5555:6666:7777:8888]"},
{name: "ipv6 with port", url: "http://[::1]:8080/path", host: "[::1]"},
{name: "ipv6 with port", url: "http://[::1234:5678]:8080/path", host: "[::1234:5678]"},
{name: "ipv6 with port", url: "http://[2001:db8::1234:5678]:8080/path", host: "[2001:db8::1234:5678]"},
{name: "ipv6 with port", url: "http://[2001:db8:3333:4444:5555:6666:7777:8888]:8080/path", host: "[2001:db8:3333:4444:5555:6666:7777:8888]"},
{name: "simple with port", url: "http://host:8080/path", host: "host"},
{name: "fqdn with port", url: "http://sub.host.com:8080/path", host: "sub.host.com"},
{name: "idna simple", url: "http://aaa😀😀😀:8080/path", host: "xn--aaa-th33baa"},
Expand Down

0 comments on commit de7916f

Please sign in to comment.