Last active
March 12, 2019 16:51
-
-
Save thapakazi/de825e1055d070862a7172fb8c7a3bae to your computer and use it in GitHub Desktop.
dump http reqeust headers with a middleware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"net/http/httputil" | |
) | |
//dump http reqeust headers | |
func App() *buffalo.App { | |
if app == nil { | |
... | |
//somewhere inside your | |
if ENV == "development" { | |
app.Use(middleware.ParameterLogger) | |
app.Use(DumpHTTPRequest) | |
} | |
... | |
} | |
} | |
// dump http headers for a request | |
func DumpHTTPRequest(next buffalo.Handler) buffalo.Handler { | |
return func(c buffalo.Context) error { | |
// Do stuff here | |
log.Println() | |
log.Println("..............") | |
req := c.Request() | |
requestDump, err := httputil.DumpRequest(req, true) | |
if err != nil { | |
log.Println(err) | |
} | |
log.Println(string(requestDump)) | |
return next(c) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment