lib/request/headers.js

1.
/**
2.
 * This is the headers class. With this class you can get the headers that were sent by the client.
3.
 * @class request.headers
4.
 * @nofunction
5.
 */
6.
class headers {
7.
	constructor(request) {
8.
		this._request = request;
9.
	}
10.

			
11.
	/**
12.
	 * With this function you can get a certain header that has been sent by the client. You 
13.
	 * specify the header you want to get using the key parameter. If the key parameter isn't a 
14.
	 * string it'll throw a TypeError and when the header wasn't found it'll return undefined.
15.
	 * @summary Returns the specified header.
16.
	 * @return {String} The specified header.
17.
	 * @function get
18.
	 */
19.
	get(key) {
20.
		return this._request.headers[key.toLowerCase()];
21.
	}
22.

			
23.
	/**
24.
	 * This function returns if the client has sent the specified header. You can specify the 
25.
	 * header you want to check using the key parameter. If the key parameter isn't a string it'll
26.
	 * throw a TypeError.
27.
	 * @summary Checks if the header exists.
28.
	 * @return {Boolean} If the header exists.
29.
	 * @function has
30.
	 */
31.
	has(key) {
32.
		return this._headers.includes(key.toLowerCase());
33.
	}
34.

			
35.
	/**
36.
	 * This function returns an array of the names of all the headers that were sent by the client.
37.
	 * @summary Returns an array of all the headers.
38.
	 * @return {String[]} An array of all the headers.
39.
	 * @function list
40.
	 */
41.
	list() {
42.
		return Object.keys(this._request.headers);
43.
	}
44.
}
45.

			
46.
module.exports = headers;