http-send
v0.0.1
Published
http send function inspired by express
Downloads
3
Readme
http-send
Http send function inspired by res.send()
of express
Supports:
- Sending of strings, buffers and streams
- Automatic
Content-Length
assignment HEAD
requests handling- Freshness checking
- ETags
Examples
var send = require('http-send')
// send hello world string
send(req, res, 'Hello world')
// do something when response were closed or finished
send(req, res, 'foo', function () {
// no chances to respond here
})
// streaming
var stream = fs.createReadStream('foo.txt')
stream.on('error', function (err) {
if (!res.headersSent) { // we can respond
res.statusCode = 500
send(req, res, err.message)
}
})
send(req, res, stream, function () {
stream.destroy()
})
Installation
npm install http-send
License
MIT