@@ -57,6 +57,15 @@ var defaultIdentifyUser = function (req, res) {
57
57
return undefined ;
58
58
} ;
59
59
60
+ var getReqHeaders = function ( req ) {
61
+ if ( req . headers ) {
62
+ return req . headers ;
63
+ } else if ( req . getHeaders ) {
64
+ return req . getHeaders ( ) || { } ;
65
+ }
66
+ return { } ;
67
+ }
68
+
60
69
/**
61
70
* @typedef {Object } MoesifOptions
62
71
* @property {string } applicationId
@@ -341,9 +350,11 @@ function makeMoesifMiddleware(options) {
341
350
var rawReqDataFromEventEmitter ;
342
351
var dataEventTracked = false ;
343
352
353
+ var reqHeaders = getReqHeaders ( req ) ;
354
+
344
355
// determines if the request is or isn't a multipart/form-data "file" type
345
- function isMultiPartUpload ( request ) {
346
- const contentTypeHeader = request . headers [ 'content-type' ] ;
356
+ function isMultiPartUpload ( ) {
357
+ const contentTypeHeader = reqHeaders && reqHeaders [ 'content-type' ] ;
347
358
if ( ! contentTypeHeader ) {
348
359
return false ;
349
360
} else if ( contentTypeHeader . indexOf ( 'multipart/form-data' ) >= 0 ) {
@@ -352,15 +363,15 @@ function makeMoesifMiddleware(options) {
352
363
return false ;
353
364
}
354
365
355
- var multiPartUpload = isMultiPartUpload ( req ) ;
366
+ var multiPartUpload = isMultiPartUpload ( ) ;
356
367
357
368
if (
358
369
options . logBody &&
359
370
! req . body &&
360
- req . headers &&
361
- req . headers [ 'content-type' ] &&
362
- req . headers [ 'content-length' ] &&
363
- parseInt ( req . headers [ 'content-length' ] ) > 0 &&
371
+ reqHeaders &&
372
+ reqHeaders [ 'content-type' ] &&
373
+ reqHeaders [ 'content-length' ] &&
374
+ parseInt ( reqHeaders [ 'content-length' ] ) > 0 &&
364
375
//if the request is "multipart/form-data" file type, we do not attempt to capture the body, otherwise we capture it
365
376
! multiPartUpload
366
377
) {
@@ -467,7 +478,7 @@ function makeMoesifMiddleware(options) {
467
478
var addTxIdToResponseStartTime = Date . now ( ) ;
468
479
let disableTransactionId = options . disableTransactionId ? options . disableTransactionId : false ;
469
480
if ( ! disableTransactionId ) {
470
- let txId = req . headers [ TRANSACTION_ID_HEADER ] || uuid4 ( ) ;
481
+ let txId = reqHeaders [ TRANSACTION_ID_HEADER ] || uuid4 ( ) ;
471
482
// Use setHeader() instead of set() so it works with plain http-module and Express
472
483
res . setHeader ( TRANSACTION_ID_HEADER , txId ) ;
473
484
}
0 commit comments