* @param {'pages' | 'dependencies' | 'data'} category * @param {Response} response * @param {string | Uint8Array} body * @param {string} decoded * @param {string} encoded * @param {string | null} referrer * @param {'linked' | 'fetched'} referenceType
(category, response, body, decoded, encoded, referrer, referenceType)
| 354 | * @param {'linked' | 'fetched'} referenceType |
| 355 | */ |
| 356 | function save(category, response, body, decoded, encoded, referrer, referenceType) { |
| 357 | const response_type = Math.floor(response.status / 100); |
| 358 | const headers = Object.fromEntries(response.headers); |
| 359 | |
| 360 | const type = headers['content-type']; |
| 361 | const is_html = response_type === REDIRECT || type === 'text/html'; |
| 362 | |
| 363 | const file = output_filename(decoded, is_html); |
| 364 | const dest = `${config.outDir}/output/prerendered/${category}/${file}`; |
| 365 | |
| 366 | if (written.has(file)) return; |
| 367 | |
| 368 | const encoded_route_id = response.headers.get('x-sveltekit-routeid'); |
| 369 | const route_id = encoded_route_id != null ? decode_uri(encoded_route_id) : null; |
| 370 | if (route_id !== null) prerendered_routes.add(route_id); |
| 371 | |
| 372 | if (response_type === REDIRECT) { |
| 373 | const location = headers['location']; |
| 374 | |
| 375 | if (location) { |
| 376 | const resolved = resolve(encoded, location); |
| 377 | if (is_root_relative(resolved)) { |
| 378 | void enqueue(decoded, decode_uri(resolved), resolved); |
| 379 | } |
| 380 | |
| 381 | if (!headers['x-sveltekit-normalize']) { |
| 382 | mkdirp(dirname(dest)); |
| 383 | |
| 384 | log.warn(`${response.status} ${decoded} -> ${location}`); |
| 385 | |
| 386 | writeFileSync( |
| 387 | dest, |
| 388 | `<script>location.href=${devalue.uneval( |
| 389 | location |
| 390 | )};</script><meta http-equiv="refresh" content="${escape_html( |
| 391 | `0;url=${location}`, |
| 392 | true |
| 393 | )}">` |
| 394 | ); |
| 395 | |
| 396 | written.add(file); |
| 397 | |
| 398 | if (!prerendered.redirects.has(decoded)) { |
| 399 | prerendered.redirects.set(decoded, { |
| 400 | status: response.status, |
| 401 | location: resolved |
| 402 | }); |
| 403 | |
| 404 | prerendered.paths.push(decoded); |
| 405 | } |
| 406 | } |
| 407 | } else { |
| 408 | log.warn(`location header missing on redirect received from ${decoded}`); |
| 409 | } |
| 410 | |
| 411 | return; |
| 412 | } |
| 413 |
no test coverage detected