Skip to content

Commit

Permalink
Server-side support for highlighting OOB reqs
Browse files Browse the repository at this point in the history
  • Loading branch information
pipeline committed Sep 27, 2023
1 parent 6cf0a6d commit ab70493
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions pkg/project/request_model_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@ func GetRequestResponseContents(w http.ResponseWriter, r *http.Request) {
return
}

maxHighlightLength, err := strconv.Atoi(r.FormValue("max_highlight_length"))
if err != nil {
// default of 50KB
maxHighlightLength = 50 * 1024
}

if httpRequest.Protocol == "Websocket" || httpRequest.Protocol == "Out of Band" {
requestResponse.DataPackets = dataPackets

Expand All @@ -463,6 +469,15 @@ func GetRequestResponseContents(w http.ResponseWriter, r *http.Request) {
requestResponse.DataPackets[idx].IsUTF8 = utf8.Valid(dpkt.Data)
}

if httpRequest.Protocol == "Out of Band" {
for _, dpkt := range requestResponse.DataPackets {
if dpkt.Direction == "Request" && requestResponse.Request == "" {
requestResponse.Request = highlightAndEncode(dpkt.Data, shouldHighlight, maxHighlightLength, false)
} else if dpkt.Direction == "Response" && requestResponse.Response == "" {
requestResponse.Response = highlightAndEncode(dpkt.Data, shouldHighlight, maxHighlightLength, false)
}
}
}
} else {
var origReq []byte
var origResp []byte
Expand Down Expand Up @@ -500,12 +515,6 @@ func GetRequestResponseContents(w http.ResponseWriter, r *http.Request) {
shouldHighlight = false
}

maxHighlightLength, err := strconv.Atoi(r.FormValue("max_highlight_length"))
if err != nil {
// default of 50KB
maxHighlightLength = 50 * 1024
}

requestResponse.Request = highlightAndEncode(origReq, shouldHighlight, maxHighlightLength, false)
requestResponse.Response = highlightAndEncode(formatResponse(origResp, contentType), shouldHighlight, maxHighlightLength, false)
requestResponse.ModifiedRequest = highlightAndEncode(modReq, shouldHighlight, maxHighlightLength, false)
Expand Down

0 comments on commit ab70493

Please sign in to comment.