Skip to content

Commit

Permalink
Add debug logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
BartVerc committed Jul 12, 2021
1 parent 65a36a9 commit dc7c644
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io/ioutil"
"log"
"net/http"
"net/url"
"regexp"
"sort"
"time"
Expand Down Expand Up @@ -89,7 +90,7 @@ func (a *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request) {

fullUrl := fmt.Sprintf("%s%s", req.URL.Host, req.URL.Path)

log.Println(fmt.Sprintf("Resolving header for %s", fullUrl))
log.Println(fmt.Sprintf("Resolving for %s", fullUrl))

requestBody, err := json.Marshal(map[string]string{
"request": fullUrl,
Expand Down Expand Up @@ -160,7 +161,13 @@ func (a *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request) {

if check.Match([]byte(path)) {
newpath := check.ReplaceAll([]byte(path), t)
req.URL.Path = string(newpath)
req.URL.Path, err = url.PathUnescape(string(newpath))
if err != nil {
log.Println("Could not rewrite Path.")
continue
}
log.Println(fmt.Sprintf("Apply rewrite: %s -> %s", path, string(newpath)))
req.RequestURI = req.URL.RequestURI()
break
}
}
Expand All @@ -169,6 +176,7 @@ func (a *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
timeDiff := time.Now().Sub(startTime)
log.Println(fmt.Sprintf("%s took %s", a.name, timeDiff))
}

a.next.ServeHTTP(rw, req)
}

Expand Down
1 change: 1 addition & 0 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func TestRouter(t *testing.T) {
handler.ServeHTTP(recorder, req)

assertCode(t, recorder, 404)
fmt.Println(req.RequestURI)
}

func assertHeader(t *testing.T, req *http.Request, key, expected string) {
Expand Down

0 comments on commit dc7c644

Please sign in to comment.