@@ -294,6 +294,7 @@ func (m *Module) ServeHTTP(w http.ResponseWriter, req *http.Request) {
294
294
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 )
295
295
}
296
296
inspin := NewRPCMsgIn (req , nil , code , size , duration , m .moduleVersion , m .serverVersion )
297
+ m .extractHeaders (req , inspin )
297
298
inspin .WAFResponse = wafresponse
298
299
inspin .HeadersOut = convertHeaders (rw .Header ())
299
300
@@ -344,18 +345,7 @@ func (m *Module) inspectorPreRequest(req *http.Request) (inspin2 RPCMsgIn2, out
344
345
}
345
346
346
347
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 )
359
349
360
350
if m .debug {
361
351
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
395
385
return
396
386
}
397
387
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
+
398
402
// inspectorPostRequest makes a postrequest call to the inspector
399
403
func (m * Module ) inspectorPostRequest (inspin * RPCMsgIn ) error {
400
404
// Create message to agent from the input request
0 commit comments