summary refs log tree commit diff stats
path: root/lib/pure/asynchttpserver.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure/asynchttpserver.nim')
-rw-r--r--lib/pure/asynchttpserver.nim15
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/pure/asynchttpserver.nim b/lib/pure/asynchttpserver.nim
index 5d74896bf..590b52c1a 100644
--- a/lib/pure/asynchttpserver.nim
+++ b/lib/pure/asynchttpserver.nim
@@ -212,7 +212,7 @@ proc processClient(client: AsyncSocket, address: string,
     if request.reqMethod == "post":
       # Check for Expect header
       if request.headers.hasKey("Expect"):
-        if request.headers["Expect"].toLower == "100-continue":
+        if request.headers.getOrDefault("Expect").toLower == "100-continue":
           await client.sendStatus("100 Continue")
         else:
           await client.sendStatus("417 Expectation Failed")
@@ -221,7 +221,8 @@ proc processClient(client: AsyncSocket, address: string,
       # - Check for Content-length header
       if request.headers.hasKey("Content-Length"):
         var contentLength = 0
-        if parseInt(request.headers["Content-Length"], contentLength) == 0:
+        if parseInt(request.headers.getOrDefault("Content-Length"),
+                    contentLength) == 0:
           await request.respond(Http400, "Bad Request. Invalid Content-Length.")
           continue
         else:
@@ -232,16 +233,18 @@ proc processClient(client: AsyncSocket, address: string,
         continue
 
     case request.reqMethod
-    of "get", "post", "head", "put", "delete", "trace", "options", "connect", "patch":
+    of "get", "post", "head", "put", "delete", "trace", "options",
+       "connect", "patch":
       await callback(request)
     else:
-      await request.respond(Http400, "Invalid request method. Got: " & request.reqMethod)
+      await request.respond(Http400, "Invalid request method. Got: " &
+        request.reqMethod)
 
     # Persistent connections
     if (request.protocol == HttpVer11 and
-        request.headers["connection"].normalize != "close") or
+        request.headers.getOrDefault("connection").normalize != "close") or
        (request.protocol == HttpVer10 and
-        request.headers["connection"].normalize == "keep-alive"):
+        request.headers.getOrDefault("connection").normalize == "keep-alive"):
       # In HTTP 1.1 we assume that connection is persistent. Unless connection
       # header states otherwise.
       # In HTTP 1.0 we assume that the connection should not be persistent.