* Flush takes our constructed response object and sends it to the client * * @private * @function flush * @param {Response} res - response * @param {String|Buffer} body - response body * @returns {Response} response
(res, body)
| 856 | * @returns {Response} response |
| 857 | */ |
| 858 | function flush(res, body) { |
| 859 | assert.ok( |
| 860 | body === null || |
| 861 | body === undefined || |
| 862 | typeof body === 'string' || |
| 863 | Buffer.isBuffer(body), |
| 864 | 'body must be a string or a Buffer instance' |
| 865 | ); |
| 866 | |
| 867 | res._data = body; |
| 868 | |
| 869 | // Flush headers |
| 870 | res.writeHead(res.statusCode); |
| 871 | |
| 872 | // Send body if it was provided |
| 873 | if (res._data) { |
| 874 | res.write(res._data); |
| 875 | } |
| 876 | |
| 877 | // Finish request |
| 878 | res.end(); |
| 879 | |
| 880 | // If log level is set to trace, log the entire response object |
| 881 | if (res.log.trace()) { |
| 882 | res.log.trace({ res: res }, 'response sent'); |
| 883 | } |
| 884 | |
| 885 | // Return the response object back out to the caller of __send |
| 886 | return res; |
| 887 | } |
| 888 | |
| 889 | /** |
| 890 | * formatterError is used to handle any case where we were unable to |
no outgoing calls
no test coverage detected