summaryrefslogtreecommitdiff
path: root/server/src/3rd/lua-uri/uri/file.lua
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-05-20 11:42:37 +0800
committersumneko <sumneko@hotmail.com>2019-05-20 11:42:37 +0800
commitc3a1a6c7e4e2f4d34d37a350aa12514fea77ad4c (patch)
tree0e70dfdfd6429a76a27ad858cb81431d2d389fee /server/src/3rd/lua-uri/uri/file.lua
parent6014825d9b1afe0af05f61c5ece7cf2b6f6b8013 (diff)
downloadlua-language-server-c3a1a6c7e4e2f4d34d37a350aa12514fea77ad4c.zip
#37 使用uri库
Diffstat (limited to 'server/src/3rd/lua-uri/uri/file.lua')
-rw-r--r--server/src/3rd/lua-uri/uri/file.lua72
1 files changed, 72 insertions, 0 deletions
diff --git a/server/src/3rd/lua-uri/uri/file.lua b/server/src/3rd/lua-uri/uri/file.lua
new file mode 100644
index 00000000..271cb3ed
--- /dev/null
+++ b/server/src/3rd/lua-uri/uri/file.lua
@@ -0,0 +1,72 @@
+local M = { _NAME = "uri.file" }
+local Util = require "uri._util"
+local URI = require "uri"
+Util.subclass_of(M, URI)
+
+function M.init (self)
+ if self:userinfo() or self:port() then
+ return nil, "usernames and passwords are not allowed in HTTP URIs"
+ end
+
+ local host = self:host()
+ local path = self:path()
+ if host then
+ if host:lower() == "localhost" then self:host("") end
+ else
+ if not path:find("^/") then
+ return nil, "file URIs must contain a host, even if it's empty"
+ end
+ self:host("")
+ end
+
+ if path == "" then self:path("/") end
+
+ return self
+end
+
+function M.host (self, ...)
+ local old = M._SUPER.host(self)
+
+ if select('#', ...) > 0 then
+ local new = ...
+ if not new then error("file URIs must have an authority part") end
+ if new:lower() == "localhost" then new = "" end
+ M._SUPER.host(self, new)
+ end
+
+ return old
+end
+
+function M.path (self, ...)
+ local old = M._SUPER.path(self)
+
+ if select('#', ...) > 0 then
+ local new = ...
+ if not new or new == "" then new = "/" end
+ M._SUPER.path(self, new)
+ end
+
+ return old
+end
+
+local function _os_implementation (os)
+ local FileImpl = Util.attempt_require("uri.file." .. os:lower())
+ if not FileImpl then
+ error("no file URI implementation for operating system " .. os)
+ end
+ return FileImpl
+end
+
+function M.filesystem_path (self, os)
+ return _os_implementation(os).filesystem_path(self)
+end
+
+function M.make_file_uri (path, os)
+ return _os_implementation(os).make_file_uri(path)
+end
+
+Util.uri_part_not_allowed(M, "userinfo")
+Util.uri_part_not_allowed(M, "port")
+
+return M
+-- vi:ts=4 sw=4 expandtab