Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hapi-common-log

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-common-log - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

6

index.js

@@ -1,4 +0,4 @@

var moment = require('moment-tokens');
var moment = require('moment-tokens');
module.exports = function toCommonLogFormat (request) {
module.exports = function toCommonLogFormat (request, options) {

@@ -11,3 +11,3 @@ var rawReq = request.raw.req;

var clientIp = request.info.remoteAddress,
var clientIp = options && options.ipHeader && request.headers[options.ipHeader] || request.info.remoteAddress,
clientId = '-',

@@ -14,0 +14,0 @@ userid = request.id,

{
"name": "hapi-common-log",
"version": "1.0.1",
"version": "1.1.0",
"description": "Parses the hapi request object to create a common log format log line",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -21,2 +21,12 @@

## Options
Sometimes you want a specific header for incoming client IP (i.e. if you've got a proxy). To customize:
```js
toCommonLogFormat(request, { ipHeader: 'x-forwarded-to' });
```
## The Common Log Format

@@ -23,0 +33,0 @@

@@ -56,2 +56,24 @@ var Lab = require('lab'),

});
});
describe('handling options', function () {
it('looks up IP from the header if desired', function (done) {
server.ext('onRequest', function (request, next) {
request.headers['x-forwarded-to'] = '123.45.678';
next();
});
server.ext('onPostHandler', function (request, next) {
var clf = toCommonLogFormat(request, {ipHeader: 'x-forwarded-to'});
var components = clf.split(' ');
expect(components[0]).to.equal('123.45.678');
next();
});
server.inject({url: '/'}, function () {
done();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc