add query string in the request log
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Simon Vieille 2023-05-27 18:11:40 +02:00
parent 5346e68c5c
commit d84612a425
Signed by: deblan
GPG key ID: 579388D585F70417
4 changed files with 47 additions and 14 deletions

View file

@ -1,5 +1,9 @@
## [Unreleased]
## v1.1.0
### Added
- add query string in the request log
## v1.0.0
### Added
- remove "retry" button and add a button for each request in the list

View file

@ -27,12 +27,13 @@ type Capture struct {
}
type Req struct {
Proto string
Method string
Url string
Path string
Header http.Header
Body []byte
Proto string `json:"proto"`
Method string `json:"method"`
Url string `json:"url"`
Path string `json:"path"`
Query string `json:"query"`
Header http.Header `json:"header"`
Body []byte `json:"body"`
}
type Res struct {
@ -54,6 +55,7 @@ type CaptureInfo struct {
type DashboardItem struct {
ID int `json:"id"`
Path string `json:"path"`
Query string `json:"query"`
Method string `json:"method"`
Status int `json:"status"`
@ -115,6 +117,7 @@ func (s *CaptureService) DashboardItems() []DashboardItem {
metadatas[i] = DashboardItem{
ID: capture.ID,
Path: capture.Req.Path,
Query: capture.Req.Query,
Method: capture.Req.Method,
Status: capture.Res.Code,
Elapsed: capture.Elapsed,

View file

@ -185,6 +185,14 @@
color: var(--disabled);
}
.query {
padding: 1rem;
font-family: inherit;
font-weight: 400;
line-height: 1.2em;
color: #fff;
}
pre {
word-break: break-all;
white-space: pre-wrap;

20
main.go
View file

@ -212,9 +212,11 @@ func NewRecorderHandler(srv *CaptureService, next http.HandlerFunc) http.Handler
Method: r.Method,
Url: r.URL.String(),
Path: r.URL.Path,
Query: extractQueryString(r.RequestURI),
Header: r.Header,
Body: reqBody.Bytes(),
}
res := Res{
Proto: rec.Result().Proto,
Status: rec.Result().Status,
@ -246,8 +248,14 @@ func NewProxyHandler(URL string) http.HandlerFunc {
func dump(c *Capture) CaptureInfo {
req := c.Req
res := c.Res
query := ""
if len(req.Query) > 1 {
query = "?" + req.Query
}
return CaptureInfo{
Request: dumpContent(req.Header, req.Body, "%s %s %s\n\n", req.Method, req.Path, req.Proto),
Request: dumpContent(req.Header, req.Body, "%s %s%s %s\n\n", req.Method, req.Path, query, req.Proto),
Response: dumpContent(res.Header, res.Body, "%s %s\n\n", res.Proto, res.Status),
Curl: dumpCurl(req),
}
@ -296,3 +304,13 @@ func dumpCurl(req Req) string {
}
return b.String()
}
func extractQueryString(uri string) string {
parts := strings.SplitN(uri, "?", 2)
if len(parts) != 2 {
return ""
}
return parts[1]
}