* This is a nonsensical custom content-type 'application/todo', just to * demonstrate how to support additional content-types. Really this is * the same as text/plain, where we pick out 'task' if available
(req, res, body, cb)
| 37 | * the same as text/plain, where we pick out 'task' if available |
| 38 | */ |
| 39 | function formatTodo(req, res, body, cb) { |
| 40 | if (body instanceof Error) { |
| 41 | res.statusCode = body.statusCode || 500; |
| 42 | body = body.message; |
| 43 | } else if (typeof body === 'object') { |
| 44 | body = body.task || JSON.stringify(body); |
| 45 | } else { |
| 46 | body = body.toString(); |
| 47 | } |
| 48 | |
| 49 | res.setHeader('Content-Length', Buffer.byteLength(body)); |
| 50 | return cb(null, body); |
| 51 | } |
| 52 | |
| 53 | ///--- Handlers |
| 54 |