all repos — nimhttpd @ 351c1377de2dccfc8c236ffd2ae08076e6472502

A useful static file web server.

Fixed error in nim 0.20.0; now handling uppercase extensions correctly (closes #1)
h3rald h3rald@h3rald.com
Sun, 23 Jun 2019 18:50:37 +0200
commit

351c1377de2dccfc8c236ffd2ae08076e6472502

parent

91ac711138d852c71ab2dbc0f6bd72dc87e6fc36

1 files changed, 6 insertions(+), 2 deletions(-)

jump to
M src/nimhttpd.nimsrc/nimhttpd.nim

@@ -74,7 +74,7 @@ var path2 = path

if cwd == "/": return path else: - path2.delete(0, cwd.len) + path2.delete(0, cwd.len-1) var relpath = path2.replace("\\", "/") if (not relpath.endsWith("/")) and (not path.existsFile): relpath = relpath&"/"

@@ -99,7 +99,11 @@ return (code: Http501, content: h_page(settings, content, $Http501), headers: newHttpHeaders())

proc sendStaticFile(settings: NimHttpSettings, path: string): NimHttpResponse = let mimes = settings.mimes - let mimetype = mimes.getMimetype(path.splitFile.ext[1 .. ^1]) + var ext = path.splitFile.ext + if ext == "": + ext = ".txt" + ext = ext[1 .. ^1] + let mimetype = mimes.getMimetype(ext.toLowerAscii) var file = path.readFile return (code: Http200, content: file, headers: {"Content-Type": mimetype}.newHttpHeaders)