[Pkg-javascript-commits] [node-mocks-http] 120/296: added .sendStatus() to mockResponse

Thorsten Alteholz alteholz at moszumanska.debian.org
Mon Feb 8 18:13:27 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 cfe205c303d3a031f3596df5a2b0d92c84d830d4
Author: Johnny Estilles <johnny.estilles at agentia.asia>
Date:   Thu Mar 19 00:44:51 2015 +0800

    added .sendStatus() to mockResponse
---
 lib/mockResponse.js | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/lib/mockResponse.js b/lib/mockResponse.js
index 4dabfe5..899ff59 100644
--- a/lib/mockResponse.js
+++ b/lib/mockResponse.js
@@ -28,6 +28,7 @@
 var WritableStream = require('./mockWritableStream');
 var EventEmitter = require('./mockEventEmitter');
 var mime = require('mime');
+var http = require('./node/http');
 
 function createResponse(options) {
 
@@ -185,6 +186,31 @@ function createResponse(options) {
     };
 
     /**
+     * Send given HTTP status code.
+     *
+     * Sets the response status to `statusCode` and the body of the
+     * response to the standard description from node's http.STATUS_CODES
+     * or the statusCode number if no description.
+     *
+     * Examples:
+     *
+     *     mockResponse.sendStatus(200);
+     *
+     * @param {number} statusCode
+     * @api public
+     */
+
+    mockResponse.sendStatus = function sendStatus(statusCode) {
+      var body = http.STATUS_CODES[statusCode] || String(statusCode);
+
+      mockResponse.statusCode = statusCode;
+      mockResponse.type('txt');
+
+      return mockResponse.send(body);
+    };
+
+
+    /**
      * Function: json
      *
      *   The 'json' function from node's HTTP API that returns JSON

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