[ci] format

This commit is contained in:
bluwy 2023-10-04 10:31:04 +00:00 committed by Martin Trapp
parent d50aaea36d
commit 9ed7da1e3b
3 changed files with 20 additions and 24 deletions

View file

@ -91,32 +91,28 @@ export function createAPIContext({
type ResponseParameters = ConstructorParameters<typeof Response>;
export class ResponseWithEncoding extends Response {
constructor(
body: ResponseParameters[0],
init: ResponseParameters[1],
encoding?: BufferEncoding
) {
// If a body string is given, try to encode it to preserve the behaviour as simple objects.
// We don't do the full handling as simple objects so users can control how headers are set instead.
if (typeof body === 'string') {
// In NodeJS, we can use Buffer.from which supports all BufferEncoding
if (typeof Buffer !== 'undefined' && Buffer.from) {
body = Buffer.from(body, encoding);
}
// In non-NodeJS, use the web-standard TextEncoder for utf-8 strings
else if (encoding == null || encoding === 'utf8' || encoding === 'utf-8') {
body = encoder.encode(body);
}
export class ResponseWithEncoding extends Response {
constructor(body: ResponseParameters[0], init: ResponseParameters[1], encoding?: BufferEncoding) {
// If a body string is given, try to encode it to preserve the behaviour as simple objects.
// We don't do the full handling as simple objects so users can control how headers are set instead.
if (typeof body === 'string') {
// In NodeJS, we can use Buffer.from which supports all BufferEncoding
if (typeof Buffer !== 'undefined' && Buffer.from) {
body = Buffer.from(body, encoding);
}
super(body, init);
if (encoding) {
this.headers.set('X-Astro-Encoding', encoding);
// In non-NodeJS, use the web-standard TextEncoder for utf-8 strings
else if (encoding == null || encoding === 'utf8' || encoding === 'utf-8') {
body = encoder.encode(body);
}
}
super(body, init);
if (encoding) {
this.headers.set('X-Astro-Encoding', encoding);
}
}
}
export async function callEndpoint<MiddlewareResult = Response | EndpointOutput>(
mod: EndpointHandler,

View file

@ -1,5 +1,5 @@
import crypto from 'node:crypto';
import buffer from 'node:buffer';
import crypto from 'node:crypto';
export function apply() {
// Remove when Node 18 is dropped for Node 20

View file

@ -13,7 +13,7 @@ export const createOutgoingHttpHeaders = (
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());