Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored and astrobot-houston committed Oct 4, 2023
1 parent 21e0757 commit b18d4bf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
38 changes: 17 additions & 21 deletions packages/astro/src/core/endpoint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
// 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);
super(body, init);

if (encoding) {
this.headers.set('X-Astro-Encoding', encoding);
}
if (encoding) {
this.headers.set('X-Astro-Encoding', encoding);
}
}
}

export async function callEndpoint<MiddlewareResult = Response | EndpointOutput>(
mod: EndpointHandler,
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/polyfill.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit b18d4bf

Please sign in to comment.