FCC-Project-HeaderParser/scripts/RequestParser.js
2025-03-20 02:01:26 +00:00

28 lines
No EOL
761 B
JavaScript

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};