diff options
author | Araq <rumpf_a@web.de> | 2010-11-18 22:26:20 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2010-11-18 22:26:20 +0100 |
commit | adf13aaea379d482ad4289d349a9d475bc2c06a6 (patch) | |
tree | 4c18d447545c35fa7c1f4ce7db566f96db67a080 /lib/pure/cgi.nim | |
parent | 8ee63f98364259b2d1b6c02d050e0efccecbcf9b (diff) | |
download | Nim-adf13aaea379d482ad4289d349a9d475bc2c06a6.tar.gz |
docgen understands and ignores *when false*
Diffstat (limited to 'lib/pure/cgi.nim')
-rwxr-xr-x | lib/pure/cgi.nim | 30 |
1 files changed, 7 insertions, 23 deletions
diff --git a/lib/pure/cgi.nim b/lib/pure/cgi.nim index 643c67bec..af222caba 100755 --- a/lib/pure/cgi.nim +++ b/lib/pure/cgi.nim @@ -7,7 +7,7 @@ # distribution, for details about the copyright. # -## This module implements helper procs for CGI applictions. Example: +## This module implements helper procs for CGI applications. Example: ## ## .. code-block:: Nimrod ## @@ -29,7 +29,7 @@ ## writeln(stdout, "your password: " & myData["password"]) ## writeln(stdout, "</body></html>") -import strutils, os, strtabs +import strutils, os, strtabs, cookies proc URLencode*(s: string): string = ## Encodes a value to be HTTP safe: This means that characters in the set @@ -355,32 +355,16 @@ proc setCookie*(name, value: string) = write(stdout, "Set-Cookie: ", name, "=", value, "\n") var - cookies: PStringTable = nil - -proc parseCookies(s: string): PStringTable = - result = newStringTable(modeCaseInsensitive) - var i = 0 - while true: - while s[i] == ' ' or s[i] == '\t': inc(i) - var keystart = i - while s[i] != '=' and s[i] != '\0': inc(i) - var keyend = i-1 - if s[i] == '\0': break - inc(i) # skip '=' - var valstart = i - while s[i] != ';' and s[i] != '\0': inc(i) - result[copy(s, keystart, keyend)] = copy(s, valstart, i-1) - if s[i] == '\0': break - inc(i) # skip ';' + gcookies: PStringTable = nil proc getCookie*(name: string): string = ## Gets a cookie. If no cookie of `name` exists, "" is returned. - if cookies == nil: cookies = parseCookies(getHttpCookie()) - result = cookies[name] + if gcookies == nil: gcookies = parseCookies(getHttpCookie()) + result = gcookies[name] proc existsCookie*(name: string): bool = ## Checks if a cookie of `name` exists. - if cookies == nil: cookies = parseCookies(getHttpCookie()) - result = hasKey(cookies, name) + if gcookies == nil: gcookies = parseCookies(getHttpCookie()) + result = hasKey(gcookies, name) |