Skip to content

Commit 48da15f

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 da1fe6c commit 48da15f

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111
- Revert all changes related to http v2 (#134).
1212
- Rewrite TAP tests with luatest.
1313
- Create a separate target for running tests in CMake.
14+
- Replace io with fio module.
1415

1516
### Added
1617

http/server.lua

Lines changed: 21 additions & 8 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)
544-
545-
if not s then
552+
local fh, err = fio.open(file, {'O_RDONLY'})
553+
if err ~= nil then
546554
return { status = 404 }
547555
end
548556

549-
local body = fh:read('*a')
550-
io.close(fh)
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
562+
563+
fh:close()
551564

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

0 commit comments

Comments
 (0)