Permalink
Browse files

Added attachment template

  • Loading branch information...
1 parent 7f17455 commit 8b6db1740433dd45adf4f8efc4e253d2ff6518d9 @dom96 committed May 13, 2012
Showing with 14 additions and 2 deletions.
  1. +10 −0 jester.nim
  2. +4 −0 tests/testapp.nim
  3. +0 −2 todo.markdown
View
@@ -393,6 +393,16 @@ template halt*(content: string): stmt =
template halt*(code: THttpCode, content: string): stmt =
halt(code, {"Content-Type": "text/html"}, content)
+template attachment*(filename = ""): stmt =
+ bind j, getMimetype
+ result[2]["Content-Disposition"] = "attachment"
+ if filename != "":
+ var param = "; filename=\"" & extractFilename(filename) & "\""
+ result[2].mget("Content-Disposition").add(param)
+ let ext = splitFile(filename).ext
+ if not (result[2]["Content-Type"] != "" or ext == ""):
+ result[2]["Content-Type"] = getMimetype(j.mimes, splitFile(filename).ext)
+
template `@`*(s: string): expr =
## Retrieves the parameter ``s`` from ``request.params``. ``""`` will be
## returned if parameter doesn't exist.
View
@@ -110,6 +110,10 @@ get "/session/@value":
setCookie("qerty", @"value", daysForward(5))
resp($request.cookies)
+get "/attachment":
+ attachment "file.html"
+ resp "blah"
+
var http = true
if paramCount() > 0:
if paramStr(1) == "scgi":
View
@@ -5,8 +5,6 @@
* More information for the TRequest object.
* request.accepts "text/xml"
* Anything else?
-* ``attachment`` function
- * Tells the browser the response should be saved to disk.
## Less important

0 comments on commit 8b6db17

Please sign in to comment.