-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix req.headers from always becoming "[CIRCULAR]" #39
base: master
Are you sure you want to change the base?
Conversation
@@ -126,7 +126,7 @@ module.exports.errorLogger = function (opts) { | |||
'response-time': responseTime, | |||
"response-hrtime": hrtime, | |||
"status-code": status, | |||
'req-headers': req.headers, | |||
'req-headers': JSON.parse(JSON.stringify(req.headers)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh. I don't like to merge that. This has a huge performance impact.
Can you try to use Object.create(req.headers)
or Object.assign({}, req.headers)` instead?
Right, that seems to be a better function choice. |
Can you show an example how to reproduce that issue? |
The following will produces a "[CIRCULAR]" in req.header in the output in console. I am not sure what test is necessary in this case, thank you.
|
Ran into this as well. Looks like the headers are already output as |
This should test the PR appropriately (it fails before the PR and passes afterwards). describe('test req.headers', function() {
var app, output;
beforeEach(function() {
app = express();
output = st();
});
it('is not circular', function(done) {
app.use(bunyanLogger({
stream: output
}));
app.get('*', function(req, res) {
res.send('test');
});
request(app)
.get('/')
.expect('GET /', function(err, res) {
var json = JSON.parse(output.content.toString());
assert.notEqual(json.req.headers, '[Circular]');
done();
});
});
}); |
This brings up another question/problem (potentially outside the scope of this PR). After this PR, it appears as thought the However, both {
...
// NOTE: req-headers is empty object
'req-headers': {},
'res-headers':
{ 'x-powered-by': 'Express',
'content-type': 'text/html; charset=utf-8',
'content-length': '4',
etag: 'W/"4-CY9rzUYh03PK3k6DJie09g"' },
req:
{ method: 'GET',
url: '/',
headers:
// NOTE: This is a parsed object
{ host: '127.0.0.1:43795',
'accept-encoding': 'gzip, deflate',
'user-agent': 'node-superagent/2.3.0',
connection: 'close' },
},
res:
{ statusCode: 200,
// NOTE: This is a raw string
header: 'HTTP/1.1 200 OK\r\nX-Powered-By: Express\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: 4\r\nETag: W/"4-CY9rzUYh03PK3k6DJie09g"\r\nDate: Tue, 03 Jan 2017 16:11:43 GMT\r\nConnection: close\r\n\r\n'},
} |
No need to change if you use the bunyan-log, |
req-headers is always "[CIRCULAR]" due to Bunyan's safeCycle() during JSON.stringify. Deep clone req.headers to req-header to overcome the same object check in safeCycle()