Home / File/ createOutgoingHttpHeaders.ts — astro Source File

createOutgoingHttpHeaders.ts — astro Source File

Architecture documentation for createOutgoingHttpHeaders.ts, a typescript file in the astro codebase. 1 imports, 0 dependents.

File typescript CoreAstro RenderingEngine 1 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  2d6507c6_d73a_ec16_4f36_6a243be56221["createOutgoingHttpHeaders.ts"]
  c2f6615e_96e9_c4eb_5f71_cf120e271705["node:http"]
  2d6507c6_d73a_ec16_4f36_6a243be56221 --> c2f6615e_96e9_c4eb_5f71_cf120e271705
  style 2d6507c6_d73a_ec16_4f36_6a243be56221 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { OutgoingHttpHeaders } from 'node:http';

/**
 * Takes in a nullable WebAPI Headers object and produces a NodeJS OutgoingHttpHeaders object suitable for usage
 * with ServerResponse.writeHead(..) or ServerResponse.setHeader(..)
 *
 * @param headers WebAPI Headers object
 * @returns {OutgoingHttpHeaders} NodeJS OutgoingHttpHeaders object with multiple set-cookie handled as an array of values
 */
export const createOutgoingHttpHeaders = (
	headers: Headers | undefined | null,
): OutgoingHttpHeaders | undefined => {
	if (!headers) {
		return undefined;
	}

	// at this point, a multi-value'd set-cookie header is invalid (it was concatenated as a single CSV, which is not valid for set-cookie)
	const nodeHeaders: OutgoingHttpHeaders = Object.fromEntries(headers.entries());

	if (Object.keys(nodeHeaders).length === 0) {
		return undefined;
	}

	// if there is > 1 set-cookie header, we have to fix it to be an array of values
	if (headers.has('set-cookie')) {
		const cookieHeaders = headers.getSetCookie();
		if (cookieHeaders.length > 1) {
			// the Headers.entries() API already normalized all header names to lower case so we can safely index this as 'set-cookie'
			nodeHeaders['set-cookie'] = cookieHeaders;
		}
	}

	return nodeHeaders;
};

Domain

Subdomains

Dependencies

  • node:http

Frequently Asked Questions

What does createOutgoingHttpHeaders.ts do?
createOutgoingHttpHeaders.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in createOutgoingHttpHeaders.ts?
createOutgoingHttpHeaders.ts defines 1 function(s): createOutgoingHttpHeaders.
What does createOutgoingHttpHeaders.ts depend on?
createOutgoingHttpHeaders.ts imports 1 module(s): node:http.
Where is createOutgoingHttpHeaders.ts in the architecture?
createOutgoingHttpHeaders.ts is located at packages/astro/src/core/app/createOutgoingHttpHeaders.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/core/app).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free