[Pkg-javascript-commits] [node-mocks-http] 193/296: ensure that using the 'headers' option when creating a request returns the headers correctly when accessed

Thorsten Alteholz alteholz at moszumanska.debian.org
Mon Feb 8 18:13:35 UTC 2016


This is an automated email from the git hooks/post-receive script.

alteholz pushed a commit to branch master
in repository node-mocks-http.

commit 723c27327fccd732740c4aae55f26a4afd16a519
Author: Anton Mostovoy <anton at mostovoy.net>
Date:   Mon Apr 13 13:52:09 2015 -0500

    ensure that using the 'headers' option when creating a request returns the headers correctly when accessed
---
 lib/mockRequest.js           | 10 +++++++++-
 test/lib/mockRequest.spec.js | 15 +++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/lib/mockRequest.js b/lib/mockRequest.js
index 9c25d12..8a93677 100644
--- a/lib/mockRequest.js
+++ b/lib/mockRequest.js
@@ -31,6 +31,14 @@
 
 var url = require('url');
 
+function convertKeysToLowerCase(map) {
+    var newMap = {};
+    for(var key in map) {
+        newMap[key.toLowerCase()] = map[key];
+    }
+    return newMap;
+}
+
 function createRequest(options) {
 
     if (!options) {
@@ -53,7 +61,7 @@ function createRequest(options) {
     if (options.signedCookies) {
         mockRequest.signedCookies = options.signedCookies;
     }
-    mockRequest.headers = (options.headers) ? options.headers : {};
+    mockRequest.headers = (options.headers) ? convertKeysToLowerCase(options.headers) : {};
     mockRequest.body = (options.body) ? options.body : {};
     mockRequest.query = (options.query) ? options.query : {};
     mockRequest.files = (options.files) ? options.files : {};
diff --git a/test/lib/mockRequest.spec.js b/test/lib/mockRequest.spec.js
index 8958da6..a08c37d 100644
--- a/test/lib/mockRequest.spec.js
+++ b/test/lib/mockRequest.spec.js
@@ -157,6 +157,21 @@ describe('mockRequest', function() {
         expect(request.headers).to.deep.equal(options.headers);
       });
 
+      it('should set .headers to options.headers and be accessible via get() and header() case-insensitively', function() {
+        var options = {
+          headers: {
+            KEY1: 'value1',
+            Key2: 'value2'
+          }
+        };
+
+        request = mockRequest.createRequest(options);
+        expect(request.header('KEY1')).to.equal('value1');
+        expect(request.get('KEY1')).to.equal('value1');
+        expect(request.header('KEY2')).to.equal('value2');
+        expect(request.get('KEY2')).to.equal('value2');
+      });
+
       it('should set .body to options.body', function() {
         var options = {
           body: {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-mocks-http.git



More information about the Pkg-javascript-commits mailing list