mirror of
https://github.com/dstotijn/hetty.git
synced 2025-07-01 18:47:29 -04:00
@ -5,6 +5,7 @@ package api
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/dstotijn/hetty/pkg/reqlog"
|
||||
)
|
||||
@ -54,18 +55,21 @@ func (r *queryResolver) HTTPRequestLog(ctx context.Context, id int64) (*HTTPRequ
|
||||
|
||||
func parseRequestLog(req reqlog.Request) (HTTPRequestLog, error) {
|
||||
method := HTTPMethod(req.Request.Method)
|
||||
if !method.IsValid() {
|
||||
if method != "" && !method.IsValid() {
|
||||
return HTTPRequestLog{}, fmt.Errorf("request has invalid method: %v", method)
|
||||
}
|
||||
|
||||
log := HTTPRequestLog{
|
||||
ID: req.ID,
|
||||
URL: req.Request.URL.String(),
|
||||
Proto: req.Request.Proto,
|
||||
Method: method,
|
||||
Timestamp: req.Timestamp,
|
||||
}
|
||||
|
||||
if req.Request.URL != nil {
|
||||
log.URL = req.Request.URL.String()
|
||||
}
|
||||
|
||||
if len(req.Body) > 0 {
|
||||
reqBody := string(req.Body)
|
||||
log.Body = &reqBody
|
||||
@ -85,11 +89,14 @@ func parseRequestLog(req reqlog.Request) (HTTPRequestLog, error) {
|
||||
|
||||
if req.Response != nil {
|
||||
log.Response = &HTTPResponseLog{
|
||||
RequestID: req.ID,
|
||||
RequestID: req.Response.RequestID,
|
||||
Proto: req.Response.Response.Proto,
|
||||
Status: req.Response.Response.Status,
|
||||
StatusCode: req.Response.Response.StatusCode,
|
||||
}
|
||||
statusReasonSubs := strings.SplitN(req.Response.Response.Status, " ", 2)
|
||||
if len(statusReasonSubs) == 2 {
|
||||
log.Response.StatusReason = statusReasonSubs[1]
|
||||
}
|
||||
if len(req.Response.Body) > 0 {
|
||||
resBody := string(req.Response.Body)
|
||||
log.Response.Body = &resBody
|
||||
|
Reference in New Issue
Block a user