~seanld/silk

683ce8509d9bc8c04b9ab760e9e5632814143385 — Sean Wilkerson 5 months ago 35e64b5 advanced-routing v0.3.6
Move mimetype DB init into global scope (inefficient)
1 files changed, 3 insertions(+), 2 deletions(-)

M src/silk/context.nim
M src/silk/context.nim => src/silk/context.nim +3 -2
@@ 9,6 9,8 @@ import std/uri
import ./headers
import ./status

let MIME_TYPES = newMimetypes()

type Context* = ref object
  conn*: AsyncSocket
  req*: Request


@@ 38,11 40,10 @@ proc sendString*(ctx: Context, str: string, mime: string = "text/plain", status:

proc getFileMimetype(path: string): string =
  let asPath = Path(path)
  let m = newMimetypes()
  let (_, _, ext) = asPath.splitFile()
  if ext == "":
    raise newException(Exception, "Mimetype required for sendFile (not given or found)")
  return m.getMimetype(ext)
  return MIME_TYPES.getMimetype(ext)

proc sendFile*(ctx: Context, path: string, mime: string = "", status: StatusCode = STATUS_OK) =
  ## `mime` can be left empty, and mimetype will be recognized