Skip to content

Commit e8ec066

Browse files
StaticFiles refactoring, Response method notFound
1 parent b616413 commit e8ec066

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "uquik",
3-
"version": "1.0.47",
3+
"version": "1.0.48",
44
"description": "uQuik HTTP(S) framework",
55
"main": "index.js",
66
"scripts": {

src/Response.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,14 @@ class Response extends Writable {
600600
throw new Error('Response.throw() expects an instance of an Error.')
601601
}
602602

603+
/**
604+
* This method calls on_not_found handler
605+
*
606+
*/
607+
notFound () {
608+
this.appHandlers.get('on_not_found')(this.wrapped_request, this)
609+
}
610+
603611
/* Response Getters */
604612

605613
/**

src/StaticFiles.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ const StaticFiles = (options = {}) => {
117117
end
118118
})
119119

120-
dataTransfer.readable.once('end', () => !dataTransfer.readable.destroyed && dataTransfer.readable.destroy())
121-
122120
res
123121
.header('Content-Type', mimeType)
124122
.header('Last-Modified', timeUTC)
@@ -129,14 +127,15 @@ const StaticFiles = (options = {}) => {
129127

130128
dataTransfer.transform = zlib.createGzip()
131129

132-
dataTransfer.transform.once('end', () => !dataTransfer.transform.destroyed && dataTransfer.transform.destroy())
133-
134-
pipeline(dataTransfer.readable, dataTransfer.transform, res, () => destroy(dataTransfer))
130+
pipeline(dataTransfer.readable, dataTransfer.transform, res, (ex) => {
131+
destroy(dataTransfer)
132+
if (ex) res.throw(ex)
133+
})
135134
} else {
136135
res.stream(dataTransfer.readable, size)
137136
}
138137
} catch (ex) {
139-
if (ex.status && ex.status === 404) return res.master_context.handlers.get('on_not_found')(req, res)
138+
if (ex.status && ex.status === 404) return res.notFound()
140139
res.throw(ex)
141140
}
142141
}

0 commit comments

Comments
 (0)