Skip to content
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

Added a optional argv for enable logging of the client\'s request headers #767

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ This will install `http-server` globally so that it may be run from the command
|`-c` |Set cache time (in seconds) for cache-control max-age header, e.g. `-c10` for 10 seconds. To disable caching, use `-c-1`.|`3600` |
|`-U` or `--utc` |Use UTC time format in log messages.| |
|`--log-ip` |Enable logging of the client's IP address |`false` |
|`--log-request-headers` |Enable logging of the client\'s request headers |`false` |
|`-P` or `--proxy` |Proxies all requests which can't be resolved locally to the given url. e.g.: -P http://someurl.com | |
|`--proxy-options` |Pass proxy [options](https://github.com/http-party/node-http-proxy#options) using nested dotted objects. e.g.: --proxy-options.secure false |
|`--username` |Username for basic authentication | |
Expand Down
4 changes: 4 additions & 0 deletions bin/http-server
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ if (argv.h || argv.help) {
' To disable timeout, use -t0',
' -U --utc Use UTC time format in log messages.',
' --log-ip Enable logging of the client\'s IP address',
' --log-request-headers Enable logging of the client\'s request headers',
'',
' -P --proxy Fallback proxy if the request cannot be resolved. e.g.: http://someurl.com',
' --proxy-options Pass options to proxy using nested dotted objects. e.g.: --proxy-options.secure false',
Expand Down Expand Up @@ -109,6 +110,9 @@ if (!argv.s && !argv.silent) {
date, ip, colors.cyan(req.method), colors.cyan(req.url),
req.headers['user-agent']
);
if(argv['log-request-headers']) {
logger.info( '[%s] %s', date, JSON.stringify({headers : req.headers }));
}
}
}
};
Expand Down
4 changes: 4 additions & 0 deletions doc/http-server.1
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ Use UTC time format in log messages.
.BI \-\-log\-ip
Enable logging of the client IP address.

.TP
.BI \-\-log\-request\-headers
Enable logging of the client\'s request headers

.TP
.BI \-P ", " \-\-proxy
Fallback proxy if the request cannot be resolved.
Expand Down