[Pkg-javascript-commits] [node-mocks-http] 89/296: added mockResponse.type()
Thorsten Alteholz
alteholz at moszumanska.debian.org
Mon Feb 8 18:13:24 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 e988baabe7a74a9bd4c70ece51e65b0b3effb9ad
Author: Johnny Estilles <johnny.estilles at agentia.asia>
Date: Sat Mar 7 17:14:49 2015 +0800
added mockResponse.type()
---
lib/mockResponse.js | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/lib/mockResponse.js b/lib/mockResponse.js
index 6f4f915..7ea5eaa 100644
--- a/lib/mockResponse.js
+++ b/lib/mockResponse.js
@@ -27,6 +27,7 @@
var WritableStream = require('./mockWritableStream');
var EventEmitter = require('./mockEventEmitter');
+var mime = require('mime');
function createResponse(options) {
@@ -211,6 +212,26 @@ function createResponse(options) {
};
/**
+ * Set "Content-Type" response header with `type` through `mime.lookup()`
+ * when it does not contain "/", or set the Content-Type to `type` otherwise.
+ *
+ * Examples:
+ *
+ * res.type('.html');
+ * res.type('html');
+ * res.type('json');
+ * res.type('application/json');
+ * res.type('png');
+ *
+ * @param {String} type
+ * @return {ServerResponse} for chaining
+ * @api public
+ */
+ mockResponse.contentType = mockResponse.type = function(type){
+ return mockResponse.set('Content-Type', type.indexOf('/') >= 0 ? type : mime.lookup(type));
+ };
+
+ /**
* Function: write
*
* This function has the same behavior as the 'send' function.
--
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