@@ -101,6 +101,22 @@ module.exports = exports = function dbScope (cfg) {
101
101
}
102
102
return str
103
103
}
104
+
105
+ function scrubRequest ( req , cloned ) {
106
+ // scrub credentials
107
+ req . url = scrubURL ( req . url )
108
+ if ( req . headers . cookie ) {
109
+ req . headers . cookie = 'XXXXXXX'
110
+ }
111
+ if ( req . auth ) {
112
+ if ( ! cloned ) {
113
+ req . auth = JSON . parse ( JSON . stringify ( req . auth ) ) // clone just auth if not already cloned
114
+ }
115
+ req . auth . username = SCRUBBED_STR
116
+ req . auth . password = SCRUBBED_STR
117
+ }
118
+ }
119
+
104
120
const responseHandler = function ( response , req , opts , resolve , reject , callback ) {
105
121
const statusCode = response . status || ( response . response && response . response . status ) || 500
106
122
if ( response . isAxiosError && response . response ) {
@@ -111,7 +127,7 @@ module.exports = exports = function dbScope (cfg) {
111
127
112
128
// let parsed
113
129
const responseHeaders = Object . assign ( {
114
- uri : req . url ,
130
+ uri : scrubURL ( req . url ) ,
115
131
statusCode : statusCode
116
132
} , response . headers )
117
133
if ( ! response . status ) {
@@ -163,11 +179,7 @@ module.exports = exports = function dbScope (cfg) {
163
179
delete body . stack
164
180
165
181
// scrub credentials
166
- req . url = scrubURL ( req . url )
167
- responseHeaders . uri = scrubURL ( responseHeaders . uri )
168
- if ( req . headers . cookie ) {
169
- req . headers . cookie = 'XXXXXXX'
170
- }
182
+ scrubRequest ( req )
171
183
172
184
log ( { err : 'couch' , body : body , headers : responseHeaders } )
173
185
@@ -201,6 +213,8 @@ module.exports = exports = function dbScope (cfg) {
201
213
}
202
214
const message = response . statusText
203
215
216
+ scrubRequest ( req )
217
+
204
218
const responseHeaders = Object . assign ( {
205
219
uri : req . url ,
206
220
statusCode : statusCode
@@ -368,11 +382,7 @@ module.exports = exports = function dbScope (cfg) {
368
382
369
383
// scrub and log
370
384
const scrubbedReq = JSON . parse ( JSON . stringify ( req ) )
371
- scrubbedReq . url = scrubURL ( scrubbedReq . url )
372
- if ( scrubbedReq . auth ) {
373
- scrubbedReq . auth . username = SCRUBBED_STR
374
- scrubbedReq . auth . password = SCRUBBED_STR
375
- }
385
+ scrubRequest ( scrubbedReq , true )
376
386
log ( scrubbedReq )
377
387
378
388
// add http agents
0 commit comments