if ( status === this.codes.SUCCESS && body && this.config.compress && ( type = this.compression( ua, encoding, headers["Content-Type"] ) ) && type !== null ) {
headers["Content-Encoding"] = REGEX_GZIP.test( type ) ? "gzip" : "deflate";
headers["Transfer-Encoding"] = "chunked";
res.writeHead( status, headers );
this.compress( req, res, body, type, headers.Etag.replace( /"/g, "" ), file );
}
else if ( file ) {
headers["Transfer-Encoding"] = "chunked";
res.writeHead( status, headers );
fs.createReadStream( body ).on( "error", function ( e ) {
self.log( e );
self.error( req, res, self.codes.SERVER_ERROR );
} ).pipe( res );
}
else {
if ( body instanceof Buffer ) {
headers["Content-Length"] = body.toString().length;
}
else if ( typeof body === "string" ) {
headers["Content-Length"] = body.length;
}
res.writeHead( status, headers );
res.end( body );
}
return this.log( this.prep( req, res ) );
};
Method respond
Send a response
Parameters:
req must be an Object.
(Request Object)
res must be an Object.
(Response Object)
body can be of any type.
(Primitive, Buffer or Stream)
status must be a Number.
([Optional] HTTP status, default is
200
)headers must be an Object.
([Optional] HTTP headers)
file must be a Boolean.
([Optional] Indicates
body
is a file path)Returns an Object
(TurtleIO instance)