-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
add super verbose, show unknown income request header and body #493
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
21f1327
feat: add super verbose, show unknown income request header and body
foxundermoon 4d8b21d
Apply suggestions from code review
foxundermoon ccf67a9
Apply suggestions from code review
foxundermoon 2f51f2c
Apply suggestions from code review
foxundermoon 1b178b8
Merge remote-tracking branch 'master'
foxundermoon a84c164
fix format
foxundermoon db3e576
add suggested
foxundermoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ if (argv.h || argv.help) { | |
' If both brotli and gzip are enabled, brotli takes precedence', | ||
' -e --ext Default file extension if none supplied [none]', | ||
' -s --silent Suppress log messages from output', | ||
' -V --superverbose superverbose mode, display request headers and body', | ||
' --cors[=headers] Enable CORS via the "Access-Control-Allow-Origin" header', | ||
' Optionally provide CORS headers list separated by commas', | ||
' -o [path] Open browser window after starting the server.', | ||
|
@@ -52,10 +53,12 @@ if (argv.h || argv.help) { | |
' -C --cert Path to ssl cert file (default: cert.pem).', | ||
' -K --key Path to ssl key file (default: key.pem).', | ||
'', | ||
|
||
' -r --robots Respond to /robots.txt [User-agent: *\\nDisallow: /]', | ||
' --no-dotfiles Do not show dotfiles', | ||
' -h --help Print this list and exit.', | ||
' -v --version Print the version and exit.' | ||
|
||
].join('\n')); | ||
process.exit(); | ||
} | ||
|
@@ -65,6 +68,7 @@ var port = argv.p || argv.port || parseInt(process.env.PORT, 10), | |
ssl = argv.S || argv.ssl, | ||
proxy = argv.P || argv.proxy, | ||
utc = argv.U || argv.utc, | ||
superverbose = argv.V || argv.superverbose, | ||
version = argv.v || argv.version, | ||
logger; | ||
|
||
|
@@ -99,6 +103,48 @@ else if (colors) { | |
request: function () {} | ||
}; | ||
} | ||
if (superverbose) { | ||
if (argv.s || argv.silent) { | ||
console.log(colors.red('superverbose and silent mode can not used together! pick one of two')); | ||
process.exit(1); | ||
} | ||
logger = { | ||
info: console.log, | ||
request: function (req, res, error) { | ||
var date = utc ? new Date().toUTCString() : new Date(); | ||
if (error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we be showing all this info if there was an error, or if there was no error? Was the logic accidentally flipped here? |
||
logger.info( | ||
'[%s] "%s %s" Error (%s): "%s"', | ||
date, colors.red(req.method), colors.red(req.url), | ||
colors.red(error.status.toString()), colors.red(error.message) | ||
); | ||
} | ||
logger.info('---------------headers-------------'); | ||
var request = req.request; | ||
var rawHeaders = request.rawHeaders; | ||
if (rawHeaders && rawHeaders.length) { | ||
var headerStr = rawHeaders.reduce(function (u, v, i) { | ||
if (i === 1) { | ||
return u + ': ' + v + '\n'; | ||
} | ||
var append = i % 2 === 0 ? ': ' : '\n' ; | ||
return u + v + append ; | ||
}); | ||
logger.info(colors.cyan(headerStr)); | ||
} | ||
if (req.readable) { | ||
var body = []; | ||
req.request.on('data', function (chunk) { | ||
body.push(chunk); | ||
}).on('end', function () { | ||
body = Buffer.concat(body).toString(); | ||
logger.info('-------------request body----------'); | ||
logger.info(body) ; | ||
}); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
if (version) { | ||
logger.info('v' + require('../package.json').version); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.