Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Other (stringify or raw text)
else {
if (!responseType) {
res.setHeader("Content-Type", "application/json; charset=utf-8");
chunk = JSON.stringify(data);
} else {
res.setHeader("Content-Type", responseType);
if (_.isString(data))
chunk = data;
else
chunk = data.toString();
}
}
// Auto generate & add ETag
if(route.etag && chunk && !res.getHeader("ETag") && !isReadableStream(chunk)) {
res.setHeader("ETag", generateETag.call(this, chunk, route.etag));
}
// Freshness
if (isFresh(req, res))
res.statusCode = 304;
if (res.statusCode === 204 || res.statusCode === 304) {
res.removeHeader("Content-Type");
res.removeHeader("Content-Length");
res.removeHeader("Transfer-Encoding");
chunk = "";
}
if (req.method === "HEAD") {
setBody(body) {
this._body = new TransformStream({ objectMode : true });
this._body._transform = function (chunk, encoding, done) {
return done(null, chunk);
};
this._lastAssignedBody = this._body;
if (isReadableStream(body)) {
body.pipe(this._body);
body.on('error', (err) => {
this._body.emit('error', err);
});
}
else if (!_.isUndefined(body)) {
this._body.end(body);
this._lastAssignedBody = body;
}
}
function isFileParam(obj) {
return Boolean(obj &&
(isstream_1.isReadable(obj) ||
Buffer.isBuffer(obj) ||
isFileObject(obj) ||
(obj.data && isFileParam(obj.data))));
}
exports.isFileParam = isFileParam;
function isFileStream(obj: any): obj is FileStream {
return obj && isReadable(obj) && obj.path;
}
constructor(options) {
if (!_.isObject(options)) {
throw new TypeError('options must be an object.');
}
const headers = options.headers;
const body = options.body;
if (headers != null && !_.isObject(headers)) {
throw new TypeError('headers must be an object.');
}
if (body != null && !isReadableStream(body)) {
throw new TypeError('body must be a readable stream.');
}
this.path = options.path;
this.method = options.method;
this._originalPath = options.originalPath || options.path;
this._headers = new Map();
_.each(headers, (v, k) => {
this._headers.set(k.toLowerCase(), v);
});
this._body = new TransformStream();
this._body._transform = function (chunk, encoding, done) {
return done(null, chunk);
};
if (isReadableStream(body)) {
function isFileStream(obj) {
return obj && isstream_1.isReadable(obj) && obj.path;
}
function isFileParam(obj) {
function isFileStream(obj: any): obj is FileStream {
return Boolean(obj && isReadable(obj) && obj.path);
}