MCPcopy
hub / github.com/dreadl0ck/netcap / readResponse

Method readResponse

decoder/stream/http/http_reader.go:282–401  ·  view source on GitHub ↗

HTTP Response

(b *bufio.Reader)

Source from the content-addressed store, hash-verified

280// HTTP Response
281
282func (h *httpReader) readResponse(b *bufio.Reader) error {
283 // try to read HTTP response from the buffered reader
284 res, err := http.ReadResponse(b, nil)
285 if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) {
286 return err
287 } else if err != nil {
288 httpLog.Debug(
289 "failed to read HTTP response",
290 zap.String("ident", h.conversation.Ident),
291 zap.Error(err),
292 )
293 return err
294 }
295
296 body, err := io.ReadAll(res.Body)
297 s := len(body)
298 if err != nil {
299 httpLog.Debug(
300 "failed to read HTTP response body",
301 zap.String("ident", h.conversation.Ident),
302 zap.Error(err),
303 zap.Int("length", s),
304 )
305 } else {
306 _ = res.Body.Close()
307
308 // Restore body so it can be read again
309 res.Body = io.NopCloser(bytes.NewBuffer(body))
310 }
311 //if h.parent.hexdump {
312 // logReassemblyInfo("Body(%d/0x%x)\n%s\n", len(body), len(body), hex.Dump(body))
313 //}
314
315 sym := ","
316 if res.ContentLength > 0 && res.ContentLength != int64(s) {
317 sym = "!="
318 }
319
320 // determine content type for debug log
321 contentType, ok := res.Header[headerContentType]
322 if !ok {
323 contentType = []string{http.DetectContentType(body)}
324 }
325
326 encoding := res.Header[headerContentEncoding]
327 httpLog.Debug("HTTP response",
328 zap.String("ident", h.conversation.Ident),
329 zap.String("Status", res.Status),
330 zap.Int64("ContentLength", res.ContentLength),
331 zap.String("sym", sym),
332 zap.Int("bodyLength", s),
333 zap.Strings("contentType", contentType),
334 zap.Strings("encoding", encoding),
335 )
336
337 // increment counter
338 streamutils.Stats.Lock()
339 streamutils.Stats.Responses++

Callers 1

DecodeMethod · 0.95

Calls 7

GetExtractorFunction · 0.92
IntMethod · 0.80
Int64Method · 0.80
CloseMethod · 0.65
ExtractFileMethod · 0.65
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected