@@ -4,6 +4,7 @@ local mime_types = require('http.mime_types')
4
4
local response = require (' http.router.response' )
5
5
6
6
local json = require (' json' )
7
+ local fio = require (' fio' )
7
8
8
9
local function type_by_format (fmt )
9
10
if fmt == nil then
@@ -62,14 +63,19 @@ local function static_file(self, request, format)
62
63
}
63
64
end
64
65
65
- local s , fh = pcall ( io.input , file )
66
+ local fh , err = fio . open ( file , { ' O_RDONLY ' } )
66
67
67
- if not s then
68
+ if err ~= nil then
68
69
return { status = 404 }
69
70
end
70
71
71
- local body = fh :read (' *a' )
72
- io.close (fh )
72
+ local body
73
+ body , err = fh :read ()
74
+ if err ~= nil then
75
+ utils .errorf (" Can not return static file for '%s': '%s'" , request :path (), err )
76
+ end
77
+
78
+ fh :close ()
73
79
74
80
if self .options .cache_static then
75
81
self .cache .static [ file ] = body
@@ -158,8 +164,18 @@ local function load_template(self, r, format)
158
164
159
165
160
166
local tpl = catfile (self .options .app_dir , ' templates' , file )
161
- local fh = io.input (tpl )
162
- local template = fh :read (' *a' )
167
+ local fh , err = fio .open (tpl )
168
+ if err ~= nil then
169
+ utils .errorf (" Can not load template for '%s': '%s'" , r .path , err )
170
+ end
171
+
172
+ local template
173
+ template , err = fh :read ()
174
+
175
+ if err ~= nil then
176
+ utils .errorf (" Can not load template for '%s': '%s'" , r .path , err )
177
+ end
178
+
163
179
fh :close ()
164
180
165
181
if self .options .cache_templates then
0 commit comments