@@ -91,32 +91,28 @@ export function createAPIContext({
91
91
92
92
type ResponseParameters = ConstructorParameters < typeof Response > ;
93
93
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 ) ;
111
106
}
107
+ }
112
108
113
- super ( body , init ) ;
109
+ super ( body , init ) ;
114
110
115
- if ( encoding ) {
116
- this . headers . set ( 'X-Astro-Encoding' , encoding ) ;
117
- }
111
+ if ( encoding ) {
112
+ this . headers . set ( 'X-Astro-Encoding' , encoding ) ;
118
113
}
119
114
}
115
+ }
120
116
121
117
export async function callEndpoint < MiddlewareResult = Response | EndpointOutput > (
122
118
mod : EndpointHandler ,
0 commit comments