summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@gmail.com>2018-02-19 12:14:45 +0000
committerDominik Picheta <dominikpicheta@gmail.com>2018-02-19 12:14:45 +0000
commit864467ade3e82c492645c3f3709613336365ba1c (patch)
tree41a6f6a35cdd2e66e1645cb0f5fe053d51413d80
parentc74a65662a052b01cf5946133dc7d77af20650da (diff)
downloadNim-864467ade3e82c492645c3f3709613336365ba1c.tar.gz
Merges #7226 manually.
-rw-r--r--lib/pure/httpclient.nim25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim
index 4c40a81fe..f81e80766 100644
--- a/lib/pure/httpclient.nim
+++ b/lib/pure/httpclient.nim
@@ -150,6 +150,31 @@ proc code*(response: Response | AsyncResponse): HttpCode
   ## corresponding ``HttpCode``.
   return response.status[0 .. 2].parseInt.HttpCode
 
+proc contentType*(response: Response | AsyncResponse): string =
+  ## Retrieves the specified response's content type.
+  ##
+  ## This is effectively the value of the "Content-Type" header.
+  response.headers.getOrDefault("content-type")
+
+proc contentLength*(response: Response | AsyncResponse): int =
+  ## Retrieves the specified response's content length.
+  ##
+  ## This is effectively the value of the "Content-Length" header.
+  ##
+  ## A ``ValueError`` exception will be raised if the value is not an integer.
+  var contentLengthHeader = response.headers.getOrDefault("Content-Length")
+  return contentLengthHeader.parseInt()
+
+proc lastModified*(response: Response | AsyncResponse): DateTime =
+  ## Retrieves the specified response's last modified time.
+  ##
+  ## This is effectively the value of the "Last-Modified" header.
+  ##
+  ## Raises a ``ValueError`` if the parsing fails or the value is not a correctly
+  ## formatted time.
+  var lastModifiedHeader = response.headers.getOrDefault("last-modified")
+  result = parse(lastModifiedHeader, "dd, dd MMM yyyy HH:mm:ss Z")
+
 proc body*(response: Response): string =
   ## Retrieves the specified response's body.
   ##