diff src/luan/modules/http/Server.luan @ 1716:b82767112d8e

add String.regex
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 24 Jul 2022 23:43:03 -0600
parents 46cf5137cb6b
children d3ea0380dfb6
line wrap: on
line diff
--- a/src/luan/modules/http/Server.luan	Sat Jul 23 21:53:04 2022 -0600
+++ b/src/luan/modules/http/Server.luan	Sun Jul 24 23:43:03 2022 -0600
@@ -1,9 +1,8 @@
 local Luan = require "luan:Luan.luan"
 local error = Luan.error
 local String = require "luan:String.luan"
-local gsub = String.gsub or error()
-local match = String.match or error()
-local matches = String.matches or error()
+local regex = String.regex or error()
+local contains = String.contains or error()
 local Io = require "luan:Io.luan"
 local uri = Io.uri or error()
 local Package = require "luan:Package.luan"
@@ -31,10 +30,10 @@
 local Server = {}
 
 function Server.init_dir(dir)
-	if not matches(dir,":") then
+	if not contains(dir,":") then
 		dir = "file:"..dir
 	end
-	dir = gsub(dir,"/$","")  -- remove trailing '/' if any
+	dir = regex("/$").gsub(dir,"")  -- remove trailing '/' if any
 	Http.dir = dir
 	Http.is_serving = true
 	function Io.schemes.site(path)
@@ -63,10 +62,12 @@
 	Thread.fork(Rpc.serve)
 end
 
+local file_regex = regex("^file:(.*)$")
+
 function Server.serve(dir,port)
 	port = port or 8080
 	Server.init_dir(dir)
-	local dir_path = match(Http.dir,"^file:(.*)$") or error "server dir must be scheme 'file:'"
+	local dir_path = file_regex.match(Http.dir) or error "server dir must be scheme 'file:'"
 	local file_handler = FileHandler.new(dir_path)
 	local luan_handler = LuanHandler.new()
 	local handler = ListHandler.new( luan_handler, file_handler )