Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Mimetypes are now looked up.

  • Loading branch information...
commit 7f17455eea68f3cf08ccc014b1bc9f6b880b69c6 1 parent 6f63791
Dominik Picheta authored
Showing with 8 additions and 7 deletions.
  1. +7 −5 jester.nim
  2. +1 −1  tests/testapp.nim
  3. +0 −1  todo.markdown
12 jester.nim
View
@@ -1,5 +1,5 @@
import httpserver, sockets, strtabs, re, tables, parseutils, os, strutils, uri,
- scgi, cookies, times
+ scgi, cookies, times, mimetypes
import patterns, errorpages, utils
@@ -15,7 +15,8 @@ type
scgiServer: TScgiState
routes*: seq[tuple[meth: TReqMeth, m: PMatch, c: TCallback]]
options: TOptions
-
+ mimes*: TMimeDb
+
TOptions = object
staticDir: string # By default ./public
appName: string
@@ -72,6 +73,7 @@ proc initOptions(j: var TJester) =
var j: TJester
j.routes = @[]
j.initOptions()
+j.mimes = newMimetypes()
proc statusContent(c: TSocket, status, content: string, headers: PStringTable, http: bool) =
var strHeaders = ""
@@ -215,9 +217,9 @@ proc handleRequest(client: TSocket, path, query, body,
# TODO: Caching.
if existsFile(j.options.staticDir / req.pathInfo):
var file = readFile(j.options.staticDir / req.pathInfo)
- # TODO: Mimetypes
- client.statusContent($Http200, file,
- {"Content-type": "text/plain"}.newStringTable, isHttp)
+ let mimetype = j.mimes.getMimetype(req.pathinfo.splitFile.ext[1 .. -1])
+ client.statusContent($Http200, file,
+ {"Content-type": mimetype}.newStringTable, isHttp)
else:
client.statusContent($Http404, error($Http404, jesterVer),
{"Content-type": "text/html"}.newStringTable, isHttp)
2  tests/testapp.nim
View
@@ -114,6 +114,6 @@ var http = true
if paramCount() > 0:
if paramStr(1) == "scgi":
http = false
-run("/jester", port = TPort(9999), http=http)
+run(if not http: "/jester" else: "", port = TPort(9999), http=http)
1  todo.markdown
View
@@ -2,7 +2,6 @@
## Important
-* Mime types
* More information for the TRequest object.
* request.accepts "text/xml"
* Anything else?
Please sign in to comment.
Something went wrong with that request. Please try again.