@@ -5,7 +5,7 @@ const path = require('path')
5
5
6
6
const { Bridge } = require ( '@vercel/node/dist/bridge' )
7
7
8
- const { downloadFile } = require ( './handlerUtils' )
8
+ const { downloadFile, getMaxAge , getMultiValueHeaders } = require ( './handlerUtils' )
9
9
10
10
const makeHandler =
11
11
( ) =>
@@ -109,22 +109,6 @@ const makeHandler =
109
109
const bridge = new Bridge ( server )
110
110
bridge . listen ( )
111
111
112
- const getMaxAge = ( header ) => {
113
- const parts = header . split ( ',' )
114
- let maxAge
115
- for ( const part of parts ) {
116
- const [ key , value ] = part . split ( '=' )
117
- if ( key ?. trim ( ) === 's-maxage' ) {
118
- maxAge = value ?. trim ( )
119
- }
120
- }
121
- if ( maxAge ) {
122
- const result = Number . parseInt ( maxAge )
123
- return Number . isNaN ( result ) ? 0 : result
124
- }
125
- return 0
126
- }
127
-
128
112
return async ( event , context ) => {
129
113
// Ensure that paths are encoded - but don't double-encode them
130
114
event . path = new URL ( event . path , event . rawUrl ) . pathname
@@ -141,14 +125,8 @@ const makeHandler =
141
125
/** @type import("@netlify/functions").HandlerResponse */
142
126
143
127
// Convert all headers to multiValueHeaders
144
- const multiValueHeaders = { }
145
- for ( const key of Object . keys ( headers ) ) {
146
- if ( Array . isArray ( headers [ key ] ) ) {
147
- multiValueHeaders [ key ] = headers [ key ]
148
- } else {
149
- multiValueHeaders [ key ] = [ headers [ key ] ]
150
- }
151
- }
128
+
129
+ const multiValueHeaders = getMultiValueHeaders ( headers )
152
130
153
131
if ( multiValueHeaders [ 'set-cookie' ] ?. [ 0 ] ?. includes ( '__prerender_bypass' ) ) {
154
132
delete multiValueHeaders . etag
@@ -163,12 +141,9 @@ const makeHandler =
163
141
if ( mode === 'odb' && process . env . EXPERIMENTAL_ODB_TTL ) {
164
142
mode = 'isr'
165
143
const ttl = getMaxAge ( cacheHeader )
166
- multiValueHeaders [ 'x-raw-ttl' ] = [ ttl ]
167
-
168
144
// Long-expiry TTL is basically no TTL
169
145
if ( ttl > 0 && ttl < ONE_YEAR_IN_SECONDS ) {
170
146
result . ttl = ttl
171
- multiValueHeaders [ 'x-ttl-result' ] = [ result . ttl ]
172
147
}
173
148
}
174
149
multiValueHeaders [ 'cache-control' ] = [ 'public, max-age=0, must-revalidate' ]
@@ -189,7 +164,7 @@ const { tmpdir } = require('os')
189
164
const { promises, existsSync } = require("fs");
190
165
// We copy the file here rather than requiring from the node module
191
166
const { Bridge } = require("./bridge");
192
- const { downloadFile } = require('./handlerUtils')
167
+ const { downloadFile, getMaxAge, getMultiValueHeaders } = require('./handlerUtils')
193
168
194
169
const { builder } = require("@netlify/functions");
195
170
const { config } = require("${ publishDir } /required-server-files.json")
0 commit comments