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

Method readRequest

decoder/stream/http/http_reader.go:423–525  ·  view source on GitHub ↗

HTTP Request

(b *bufio.Reader)

Source from the content-addressed store, hash-verified

421// HTTP Request
422
423func (h *httpReader) readRequest(b *bufio.Reader) error {
424 // Extract header order for JA4H fingerprinting before parsing
425 // We need to peek at the raw bytes to preserve header order
426 headerOrder, cookieFields, acceptLang := extractHeaderOrderFromReader(b)
427
428 req, err := http.ReadRequest(b)
429 if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) {
430 return err
431 } else if err != nil {
432 httpLog.Error(
433 "failed to read HTTP request",
434 zap.String("ident", h.conversation.Ident),
435 zap.Error(err),
436 )
437 return err
438 }
439
440 body, err := io.ReadAll(req.Body)
441 s := len(body)
442 if err != nil {
443 httpLog.Error(
444 "failed to read HTTP request body",
445 zap.String("ident", h.conversation.Ident),
446 zap.Error(err),
447 zap.Int("length", s),
448 )
449 // continue execution
450 } else {
451 _ = req.Body.Close()
452
453 // Restore body so it can be read again
454 req.Body = io.NopCloser(bytes.NewBuffer(body))
455 }
456 //if h.tcpStreamReader.hexdump {
457 // logReassemblyInfo("Body(%d/0x%x)\n%s\n", len(body), len(body), hex.Dump(body))
458 //}
459
460 httpLog.Debug("HTTP request",
461 zap.String("ident", h.conversation.Ident),
462 zap.String("method", req.Method),
463 zap.String("url", req.URL.String()),
464 zap.Int("bodyLength", s),
465 )
466
467 t := h.conversation.FirstClientPacket.UnixNano()
468
469 request := &httpRequest{
470 request: req,
471 timestamp: t,
472 clientIP: h.conversation.ClientIP,
473 serverIP: h.conversation.ServerIP,
474 clientPort: h.conversation.ClientPort,
475 serverPort: h.conversation.ServerPort,
476 flow: h.conversation.Ident,
477 headerOrder: headerOrder,
478 cookieFields: cookieFields,
479 acceptLang: acceptLang,
480 }

Callers 1

DecodeMethod · 0.95

Calls 7

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

Tested by

no test coverage detected