[ci] format
This commit is contained in:
parent
21e0757ea2
commit
b18d4bf3b1
3 changed files with 20 additions and 24 deletions
|
@ -91,32 +91,28 @@ export function createAPIContext({
|
||||||
|
|
||||||
type ResponseParameters = ConstructorParameters<typeof Response>;
|
type ResponseParameters = ConstructorParameters<typeof Response>;
|
||||||
|
|
||||||
export class ResponseWithEncoding extends Response {
|
export class ResponseWithEncoding extends Response {
|
||||||
constructor(
|
constructor(body: ResponseParameters[0], init: ResponseParameters[1], encoding?: BufferEncoding) {
|
||||||
body: ResponseParameters[0],
|
// If a body string is given, try to encode it to preserve the behaviour as simple objects.
|
||||||
init: ResponseParameters[1],
|
// We don't do the full handling as simple objects so users can control how headers are set instead.
|
||||||
encoding?: BufferEncoding
|
if (typeof body === 'string') {
|
||||||
) {
|
// In NodeJS, we can use Buffer.from which supports all BufferEncoding
|
||||||
// If a body string is given, try to encode it to preserve the behaviour as simple objects.
|
if (typeof Buffer !== 'undefined' && Buffer.from) {
|
||||||
// We don't do the full handling as simple objects so users can control how headers are set instead.
|
body = Buffer.from(body, encoding);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// In non-NodeJS, use the web-standard TextEncoder for utf-8 strings
|
||||||
super(body, init);
|
else if (encoding == null || encoding === 'utf8' || encoding === 'utf-8') {
|
||||||
|
body = encoder.encode(body);
|
||||||
if (encoding) {
|
|
||||||
this.headers.set('X-Astro-Encoding', encoding);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
super(body, init);
|
||||||
|
|
||||||
|
if (encoding) {
|
||||||
|
this.headers.set('X-Astro-Encoding', encoding);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function callEndpoint<MiddlewareResult = Response | EndpointOutput>(
|
export async function callEndpoint<MiddlewareResult = Response | EndpointOutput>(
|
||||||
mod: EndpointHandler,
|
mod: EndpointHandler,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import crypto from 'node:crypto';
|
|
||||||
import buffer from 'node:buffer';
|
import buffer from 'node:buffer';
|
||||||
|
import crypto from 'node:crypto';
|
||||||
|
|
||||||
export function apply() {
|
export function apply() {
|
||||||
// Remove when Node 18 is dropped for Node 20
|
// Remove when Node 18 is dropped for Node 20
|
||||||
|
|
Loading…
Reference in a new issue