quinn-respond
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -37,3 +37,23 @@ 'use strict'; | ||
this._headers = c; | ||
this.body(body); | ||
} | ||
QuinnResponse.prototype.header = | ||
function header(key, value, clobber) { | ||
this._headers.set(key, value, clobber); | ||
return this; | ||
}; | ||
QuinnResponse.prototype.status = | ||
function status(code) { | ||
this.statusCode = code; | ||
return this; | ||
}; | ||
QuinnResponse.prototype.body = | ||
function body(body) { | ||
if (body === undefined) { | ||
return this; | ||
} | ||
if (typeof body === 'string') { | ||
@@ -47,17 +67,28 @@ body = new Buffer(body, 'utf8'); | ||
this.body = bodyToStream(body); | ||
} | ||
body = bodyToStream(body); | ||
QuinnResponse.prototype.header = | ||
function header(key, value, clobber) { | ||
this._headers.set(key, value, clobber); | ||
if (this._body === undefined) { | ||
this._body = body; | ||
} else { | ||
body.pipe(this._body); | ||
} | ||
return this; | ||
}; | ||
QuinnResponse.prototype.status = | ||
function status(code) { | ||
this.statusCode = code; | ||
return this; | ||
QuinnResponse.prototype.text = function(body) { | ||
return this.body(body) | ||
.header('Content-Type', 'text/plain; charset=utf-8'); | ||
}; | ||
QuinnResponse.prototype.html = function(body) { | ||
return this.body(body) | ||
.header('Content-Type', 'text/html; charset=utf-8'); | ||
}; | ||
QuinnResponse.prototype.json = function(data, visitor, indent) { | ||
return this.body(JSON.stringify(data, visitor, indent)) | ||
.header('Content-Type', 'application/json; charset=utf-8'); | ||
}; | ||
QuinnResponse.prototype._forwardMeta = | ||
@@ -82,3 +113,3 @@ function _forwardMeta(dest) { | ||
return this.body.pipe(target); | ||
return this._body.pipe(target); | ||
}; | ||
@@ -126,5 +157,3 @@ | ||
function json(data, visitor, indent) { | ||
var body = JSON.stringify(data, visitor, indent); | ||
return respond({ body: body }) | ||
.header('Content-Type', 'application/json; charset=utf-8'); | ||
return respond().json(data, visitor, indent); | ||
} | ||
@@ -131,0 +160,0 @@ respond.json = json; |
{ | ||
"name": "quinn-respond", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Response generation for quinn", | ||
@@ -5,0 +5,0 @@ "main": "lib/respond.js", |
@@ -16,3 +16,3 @@ /*global describe, it */ | ||
server.makeRequest(function() { | ||
return respond.text('ok') | ||
return respond().text('ok') | ||
.status(201); | ||
@@ -33,3 +33,3 @@ }).then(function(res) { | ||
// http://stackoverflow.com/questions/9864662/how-to-get-the-string-length-in-bytes-in-nodejs | ||
return respond.html('äáöü') | ||
return respond().html('äáöü') | ||
.status(201); | ||
@@ -49,3 +49,3 @@ }).then(function(res) { | ||
server.makeRequest(function() { | ||
return respond.json({ x: 2 }); | ||
return respond().json({ x: 2 }); | ||
}).then(function(res) { | ||
@@ -61,3 +61,3 @@ assert.equal('{"x":2}', res.body); | ||
server.makeRequest(function() { | ||
return respond.json({ x: 2 }, null, 2); | ||
return respond().json({ x: 2 }, null, 2); | ||
}).then(function(res) { | ||
@@ -64,0 +64,0 @@ assert.equal('{\n "x": 2\n}', res.body); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
14082
384
1