@@ -8,31 +8,40 @@ import type { APIRequest, ServerRequest, ServerResponse } from '../types.ts'
88let brotli : ( ( data : Uint8Array ) => Uint8Array ) | null = null
99let gzip : ( ( data : Uint8Array ) => Uint8Array ) | null = null
1010
11+ type Response = {
12+ status : number
13+ headers : Headers
14+ compress : boolean
15+ done : boolean
16+ }
17+
1118export class Request implements APIRequest {
1219 #req: ServerRequest
1320 #params: Record < string , string >
1421 #query: URLSearchParams
1522 #cookies: ReadonlyMap < string , string >
16- #resp = {
17- status : 200 ,
18- headers : new Headers ( {
19- Server : 'Aleph.js' ,
20- } ) ,
21- done : false
22- }
23+ #resp: Response
2324
24- constructor ( req : ServerRequest , params : Record < string , string > , query : URLSearchParams ) {
25+ constructor ( req : ServerRequest , params : Record < string , string > , query : URLSearchParams , compress : boolean = true ) {
2526 this . #req = req
2627 this . #params = params
2728 this . #query = query
2829 const cookies = new Map ( )
2930 this . headers . get ( 'cookie' ) ?. split ( ';' ) . forEach ( cookie => {
30- const p = cookie . trim ( ) . split ( '=' )
31+ const p = cookie . split ( '=' )
3132 if ( p . length >= 2 ) {
32- cookies . set ( p . shift ( ) ! . trim ( ) , decodeURI ( p . join ( '=' ) ) )
33+ cookies . set ( p . shift ( ) ! , decodeURI ( p . join ( '=' ) ) )
3334 }
3435 } )
3536 this . #cookies = cookies
37+ this . #resp = {
38+ status : 200 ,
39+ headers : new Headers ( {
40+ Server : 'Aleph.js' ,
41+ } ) ,
42+ compress,
43+ done : false
44+ }
3645 }
3746
3847 get url ( ) : string {
@@ -159,12 +168,12 @@ export class Request implements APIRequest {
159168 contentType = 'text/plain; charset=utf-8'
160169 this . #resp. headers . set ( 'Content-Type' , contentType )
161170 }
162- if ( Deno . env . get ( 'ALEPH_BUILD_MODE' ) !== 'development' ) {
171+ if ( this . #resp . compress ) {
163172 let shouldCompress = false
164173 if ( contentType ) {
165174 if ( contentType . startsWith ( 'text/' ) ) {
166175 shouldCompress = true
167- } else if ( / ^ a p p l i c a t i o n \/ ( j a v a s c r i p t | t y p e c r i p t | w a s m | j s o n | x m l ) / i. test ( contentType ) ) {
176+ } else if ( / ^ a p p l i c a t i o n \/ ( j a v a s c r i p t | j s o n | x m l | w a s m ) / i. test ( contentType ) ) {
168177 shouldCompress = true
169178 } else if ( / ^ i m a g e \/ s v g \+ x m l / i. test ( contentType ) ) {
170179 shouldCompress = true
0 commit comments