From 34309335b12cf691d269560b284087e105416f21 Mon Sep 17 00:00:00 2001 From: Jeremy Thomerson Date: Thu, 17 Jan 2019 15:16:21 -0500 Subject: [PATCH] Add helper methods to request class --- lib/request.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/request.js b/lib/request.js index f2bedd0..6443a7c 100644 --- a/lib/request.js +++ b/lib/request.js @@ -269,6 +269,25 @@ class REQUEST { || (wc.length > 1 && this.validWildcard(wc.slice(0,-1))) } + // Gets a header field (case-insensitive) + getHeader(userKey,asArr) { + let key = (userKey || '').toLowerCase() + + return asArr ? this.headers[key] + : this.headers[key] ? + this.headers[key].toString() : undefined + } + + // Returns boolean if header exists + hasHeader(key) { + return this.getHeader(key ? key : '') !== undefined + } + + // Gets a value from the query string + getQuery(key,asArr) { + return asArr ? this.multiValueQuery[key] : this.query[key] + } + } // end REQUEST class // Export the response object