https://github.com/softonic/node-http-log-format
Functions to transform native Node.js HTTP requests and responses to the Softonic HTTP log format
https://github.com/softonic/node-http-log-format
Last synced: 12 months ago
JSON representation
Functions to transform native Node.js HTTP requests and responses to the Softonic HTTP log format
- Host: GitHub
- URL: https://github.com/softonic/node-http-log-format
- Owner: softonic
- License: other
- Created: 2017-03-14T15:06:00.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-02-03T16:11:41.000Z (over 6 years ago)
- Last Synced: 2025-05-14T17:54:44.580Z (about 1 year ago)
- Language: JavaScript
- Size: 91.8 KB
- Stars: 0
- Watchers: 8
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @softonic/http-log-format
Functions to transform native Node.js HTTP requests and responses to the Softonic HTTP log format
## Installation
```bash
npm install @softonic/http-log-format
```
## Usage
```js
// CommonJS
// const http = require('http');
// const {
// formatRequest,
// formatResponse,
// stringifyRequest,
// stringifyResponse,
// } = require('@softonic/http-log-format');
// ES2015
import http from 'http';
import {
formatRequest,
formatResponse,
stringifyRequest,
stringifyResponse,
} from '@softonic/http-log-format';
http.createServer((req, res) => {
// send response...
const formattedRequest = formatRequest(req, {
// whitelist and blacklist should not be used together
whitelistHeaders: ['accept', 'accept-language', 'host'],
blacklistHeaders: ['cookie'],
});
const formattedResponse = formatResponse(res, {
// whitelist and blacklist should not be used together
whitelistHeaders: ['content-type', 'content-language', 'content-length'],
blacklistHeaders: ['set-cookie'],
});
const message = `${stringifyRequest(req) ${stringifyResponse(res)}}`;
// Some logger instance
logger.info({
request: formattedResponse,
response: formattedResponse,
}, message);
});
http.request(options, (res) => {
// process response...
const formattedRequest = formatRequest(res.req, {
// whitelist and blacklist should not be used together
whitelistHeaders: ['accept', 'accept-language', 'host'],
blacklistHeaders: ['cookie'],
});
const formattedResponse = formatResponse(res, {
// whitelist and blacklist should not be used together
whitelistHeaders: ['content-type', 'content-language', 'content-length'],
blacklistHeaders: ['set-cookie'],
});
const message = `${stringifyRequest(res.req) ${stringifyResponse(res)}}`;
// Some logger instance
logger.info({
request: formattedResponse,
response: formattedResponse,
}, message);
});
```
## Testing
Clone the repository and execute:
```bash
npm test
```
## Contribute
1. Fork it: `git clone https://github.com/softonic/node-http-log-format.git`
2. Create your feature branch: `git checkout -b feature/my-new-feature`
3. Commit your changes: `git commit -am 'Added some feature'`
4. Check the build: `npm run build`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D