1 | 'use strict'
|
2 | function headRouteOnSendHandler (req, reply, payload, done) {
|
3 |
|
4 | if (payload === undefined) {
|
5 | reply.header('content-length', '0')
|
6 | return done(null, null)
|
7 | }
|
8 |
|
9 | if (typeof payload.resume === 'function') {
|
10 | payload.on('error', (err) => {
|
11 | reply.log.error({ err }, 'Error on Stream found for HEAD route')
|
12 | })
|
13 | payload.resume()
|
14 | return done(null, null)
|
15 | }
|
16 |
|
17 | const size = '' + Buffer.byteLength(payload)
|
18 |
|
19 | reply.header('content-length', size)
|
20 |
|
21 | done(null, null)
|
22 | }
|
23 |
|
24 | function parseHeadOnSendHandlers (onSendHandlers) {
|
25 | if (onSendHandlers == null) return headRouteOnSendHandler
|
26 | return Array.isArray(onSendHandlers) ? [...onSendHandlers, headRouteOnSendHandler] : [onSendHandlers, headRouteOnSendHandler]
|
27 | }
|
28 |
|
29 | module.exports = {
|
30 | parseHeadOnSendHandlers
|
31 | }
|