Skip to content

Commit 36eefaf

Browse files
committed
http: replace io with fio module
In tarantool the standart built-in module for working with files is "fio". So we should use it instead of "io". Patch adds a commit 'Get rid of io module' (e0d8f82) that was implemented for http v2 and later reverted in scope of issue with discard v2. Follows up #90 Part of #134
1 parent a10c59c commit 36eefaf

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

http/server.lua

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
local lib = require('http.lib')
44

5-
local io = io
5+
local fio = require('fio')
66
local require = require
77
local package = package
88
local mime_types = require('http.mime_types')
@@ -349,8 +349,17 @@ local function load_template(self, r, format)
349349

350350

351351
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+
354363
fh:close()
355364

356365
if self.options.cache_templates then
@@ -540,14 +549,18 @@ local function static_file(self, request, format)
540549
}
541550
end
542551

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
544556

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
548562

549-
local body = fh:read('*a')
550-
io.close(fh)
563+
fh:close()
551564

552565
if self.options.cache_static then
553566
self.cache.static[ file ] = body

0 commit comments

Comments
 (0)