Skip to content
Open
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
17 changes: 8 additions & 9 deletions runtime/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ package zanzibar

import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/http/httputil"
"net/url"

"github.com/opentracing/opentracing-go"
Expand All @@ -45,13 +45,12 @@ const (
//
// This router has support for decoding path "parameters" in the URL into named values. An example:
//
// var r zanzibar.HTTPRouter
//
// r.Handle("GET", "/foo/:bar", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// params := zanzibar.ParamsFromContext(r.Context())
// w.Write("%s", params.Get("bar"))
// }))
// var r zanzibar.HTTPRouter
//
// r.Handle("GET", "/foo/:bar", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// params := zanzibar.ParamsFromContext(r.Context())
// w.Write("%s", params.Get("bar"))
// }))
type HTTPRouter interface {
// HTTPRouter implements a http.Handle as a convenience to allow HTTPRouter to be invoked by the standard library HTTP server.
http.Handler
Expand Down Expand Up @@ -216,14 +215,14 @@ func (router *httpRouter) handlePanic(
if !ok {
err = errors.Wrap(err, "wrapped")
}
if reqheaderBytes, err2 := httputil.DumpRequestOut(r, true); err2 != nil {
if reqheaderBytes, err2 := json.Marshal(r.Header); err2 == nil {
router.gateway.Logger.Error(
"A http request handler paniced",
zap.Error(err),
zap.String("pathname", r.URL.RequestURI()),
zap.String("host", r.Host),
zap.String("remoteAddr", r.RemoteAddr),
zap.String("request", string(reqheaderBytes)),
zap.String("header", string(reqheaderBytes)),
)
} else {
router.gateway.Logger.Error(
Expand Down