@@ -91,32 +91,28 @@ export function createAPIContext({
9191
9292type ResponseParameters = ConstructorParameters < typeof Response > ;
9393
94- export class ResponseWithEncoding extends Response {
95- constructor (
96- body : ResponseParameters [ 0 ] ,
97- init : ResponseParameters [ 1 ] ,
98- encoding ?: BufferEncoding
99- ) {
100- // If a body string is given, try to encode it to preserve the behaviour as simple objects.
101- // We don't do the full handling as simple objects so users can control how headers are set instead.
102- if ( typeof body === 'string' ) {
103- // In NodeJS, we can use Buffer.from which supports all BufferEncoding
104- if ( typeof Buffer !== 'undefined' && Buffer . from ) {
105- body = Buffer . from ( body , encoding ) ;
106- }
107- // In non-NodeJS, use the web-standard TextEncoder for utf-8 strings
108- else if ( encoding == null || encoding === 'utf8' || encoding === 'utf-8' ) {
109- body = encoder . encode ( body ) ;
110- }
94+ export class ResponseWithEncoding extends Response {
95+ constructor ( body : ResponseParameters [ 0 ] , init : ResponseParameters [ 1 ] , encoding ?: BufferEncoding ) {
96+ // If a body string is given, try to encode it to preserve the behaviour as simple objects.
97+ // We don't do the full handling as simple objects so users can control how headers are set instead.
98+ if ( typeof body === 'string' ) {
99+ // In NodeJS, we can use Buffer.from which supports all BufferEncoding
100+ if ( typeof Buffer !== 'undefined' && Buffer . from ) {
101+ body = Buffer . from ( body , encoding ) ;
102+ }
103+ // In non-NodeJS, use the web-standard TextEncoder for utf-8 strings
104+ else if ( encoding == null || encoding === 'utf8' || encoding === 'utf-8' ) {
105+ body = encoder . encode ( body ) ;
111106 }
107+ }
112108
113- super ( body , init ) ;
109+ super ( body , init ) ;
114110
115- if ( encoding ) {
116- this . headers . set ( 'X-Astro-Encoding' , encoding ) ;
117- }
111+ if ( encoding ) {
112+ this . headers . set ( 'X-Astro-Encoding' , encoding ) ;
118113 }
119114 }
115+ }
120116
121117export async function callEndpoint < MiddlewareResult = Response | EndpointOutput > (
122118 mod : EndpointHandler ,
0 commit comments