@@ -70,15 +70,18 @@ async function send (ctx, path, opts = {}) {
70
70
// hidden file support, ignore
71
71
if ( ! hidden && isHidden ( root , path ) ) return
72
72
73
+ let encodingExt = ''
73
74
// serve brotli file when possible otherwise gzipped file when possible
74
- if ( ctx . acceptsEncodings ( 'br' , 'deflate' , ' identity') === 'br' && brotli && ( await fs . exists ( path + '.br' ) ) ) {
75
+ if ( ctx . acceptsEncodings ( 'br' , 'identity' ) === 'br' && brotli && ( await fs . exists ( path + '.br' ) ) ) {
75
76
path = path + '.br'
76
77
ctx . set ( 'Content-Encoding' , 'br' )
77
78
ctx . res . removeHeader ( 'Content-Length' )
78
- } else if ( ctx . acceptsEncodings ( 'gzip' , 'deflate' , 'identity' ) === 'gzip' && gzip && ( await fs . exists ( path + '.gz' ) ) ) {
79
+ encodingExt = '.br'
80
+ } else if ( ctx . acceptsEncodings ( 'gzip' , 'identity' ) === 'gzip' && gzip && ( await fs . exists ( path + '.gz' ) ) ) {
79
81
path = path + '.gz'
80
82
ctx . set ( 'Content-Encoding' , 'gzip' )
81
83
ctx . res . removeHeader ( 'Content-Length' )
84
+ encodingExt = '.gz'
82
85
}
83
86
84
87
if ( extensions && ! / \. .* $ / . exec ( path ) ) {
@@ -133,9 +136,8 @@ async function send (ctx, path, opts = {}) {
133
136
}
134
137
ctx . set ( 'Cache-Control' , directives . join ( ',' ) )
135
138
}
136
- ctx . type = type ( path )
139
+ ctx . type = type ( path , encodingExt )
137
140
ctx . body = fs . createReadStream ( path )
138
-
139
141
return path
140
142
}
141
143
@@ -155,8 +157,8 @@ function isHidden (root, path) {
155
157
* File type.
156
158
*/
157
159
158
- function type ( file ) {
159
- return extname ( basename ( file , '.gz' ) )
160
+ function type ( file , ext ) {
161
+ return ext !== '' ? extname ( basename ( file , ext ) ) : extname ( file )
160
162
}
161
163
162
164
/**
0 commit comments