|
2 | 2 |
|
3 | 3 | local lib = require('http.lib')
|
4 | 4 |
|
5 |
| -local io = io |
| 5 | +local fio = require('fio') |
6 | 6 | local require = require
|
7 | 7 | local package = package
|
8 | 8 | local mime_types = require('http.mime_types')
|
@@ -349,8 +349,17 @@ local function load_template(self, r, format)
|
349 | 349 |
|
350 | 350 |
|
351 | 351 | local tpl = catfile(self.options.app_dir, 'templates', file)
|
352 |
| - local fh = io.input(tpl) |
353 |
| - local template = fh:read('*a') |
| 352 | + local fh, err = fio.open(tpl) |
| 353 | + if err ~= nil then |
| 354 | + errorf("Can not load template for '%s': '%s'", r.path, err) |
| 355 | + end |
| 356 | + |
| 357 | + local template |
| 358 | + template, err = fh:read() |
| 359 | + if err ~= nil then |
| 360 | + errorf("Can not load template for '%s': '%s'", r.path, err) |
| 361 | + end |
| 362 | + |
354 | 363 | fh:close()
|
355 | 364 |
|
356 | 365 | if self.options.cache_templates then
|
@@ -540,14 +549,18 @@ local function static_file(self, request, format)
|
540 | 549 | }
|
541 | 550 | end
|
542 | 551 |
|
543 |
| - local s, fh = pcall(io.input, file) |
| 552 | + local fh, err = fio.open(file, {'O_RDONLY'}) |
| 553 | + if err ~= nil then |
| 554 | + return { status = 404 } |
| 555 | + end |
544 | 556 |
|
545 |
| - if not s then |
546 |
| - return { status = 404 } |
547 |
| - end |
| 557 | + local body |
| 558 | + body, err = fh:read() |
| 559 | + if err ~= nil then |
| 560 | + errorf("Can not return static file for '%s': '%s'", request:path(), err) |
| 561 | + end |
548 | 562 |
|
549 |
| - local body = fh:read('*a') |
550 |
| - io.close(fh) |
| 563 | + fh:close() |
551 | 564 |
|
552 | 565 | if self.options.cache_static then
|
553 | 566 | self.cache.static[ file ] = body
|
|
0 commit comments