Skip to content

Commit 39ba35f

Browse files
Added header extraction to postRequest #18874 (#10)
Added header extraction to postRequest #18874
2 parents 4ed2f5a + a83d4ec commit 39ba35f

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

module.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ func (m *Module) ServeHTTP(w http.ResponseWriter, req *http.Request) {
294294
log.Printf("DEBUG: calling 'RPC.PostRequest' due to anomaly: method=%s host=%s url=%s code=%d size=%d duration=%s", req.Method, req.Host, req.URL, code, size, duration)
295295
}
296296
inspin := NewRPCMsgIn(req, nil, code, size, duration, m.moduleVersion, m.serverVersion)
297+
m.extractHeaders(req, inspin)
297298
inspin.WAFResponse = wafresponse
298299
inspin.HeadersOut = convertHeaders(rw.Header())
299300

@@ -344,18 +345,7 @@ func (m *Module) inspectorPreRequest(req *http.Request) (inspin2 RPCMsgIn2, out
344345
}
345346

346347
inspin := NewRPCMsgIn(req, reqbody, -1, -1, -1, m.moduleVersion, m.serverVersion)
347-
348-
// If the user supplied a custom header extractor, use it to unpack the
349-
// headers. If there no custom header extractor or it returns an error,
350-
// fallback to the native headers on the request.
351-
if m.headerExtractor != nil {
352-
hin, err := m.headerExtractor(req)
353-
if err == nil {
354-
inspin.HeadersIn = convertHeaders(hin)
355-
} else if m.debug {
356-
log.Printf("DEBUG: Error extracting custom headers, using native headers: %s", err)
357-
}
358-
}
348+
m.extractHeaders(req, inspin)
359349

360350
if m.debug {
361351
log.Printf("DEBUG: Making PreRequest call to inspector: %s %s", inspin.Method, inspin.URI)
@@ -395,6 +385,20 @@ func (m *Module) inspectorPreRequest(req *http.Request) (inspin2 RPCMsgIn2, out
395385
return
396386
}
397387

388+
func (m *Module) extractHeaders(req *http.Request, inspin *RPCMsgIn) {
389+
// If the user supplied a custom header extractor, use it to unpack the
390+
// headers. If there no custom header extractor or it returns an error,
391+
// fallback to the native headers on the request.
392+
if m.headerExtractor != nil {
393+
hin, err := m.headerExtractor(req)
394+
if err == nil {
395+
inspin.HeadersIn = convertHeaders(hin)
396+
} else if m.debug {
397+
log.Printf("DEBUG: Error extracting custom headers, using native headers: %s", err)
398+
}
399+
}
400+
}
401+
398402
// inspectorPostRequest makes a postrequest call to the inspector
399403
func (m *Module) inspectorPostRequest(inspin *RPCMsgIn) error {
400404
// Create message to agent from the input request

0 commit comments

Comments
 (0)