Add request parser and formatter
This commit is contained in:
parent
6236669e4b
commit
0fd5fb3ab1
1 changed files with 28 additions and 0 deletions
28
scripts/RequestParser.js
Normal file
28
scripts/RequestParser.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
class RequestParser {
|
||||
/**
|
||||
Parse a new request.
|
||||
|
||||
@param {object} REQUEST - The request object
|
||||
*/
|
||||
constructor(REQUEST) {
|
||||
if (REQUEST ? (Object.keys(REQUEST).length) : false) {
|
||||
this[`request`] = REQUEST
|
||||
}
|
||||
else {throw new Error()};
|
||||
}
|
||||
|
||||
/**
|
||||
Get and format the headers from the request.
|
||||
|
||||
@returns {object} - The headers
|
||||
*/
|
||||
getHeaders() {
|
||||
this[`headers`] = this[`request`][`headers`]
|
||||
this[`headers`][`ipaddress`] = this[`request`][`ip`];
|
||||
this[`headers`][`software`] = this[`headers`][`user-agent`];
|
||||
this[`headers`][`language`] = this[`headers`]["accept-language"];
|
||||
return this[`headers`];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {RequestParser};
|
Loading…
Add table
Add a link
Reference in a new issue