about summary refs log tree commit diff stats
path: root/src/loader
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-27 02:48:21 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-27 02:51:41 +0200
commitac3e737867245ac65adfa2352ce6e7fdacc57b18 (patch)
treee747a5891176c7dce618bafaf79d750d5a40416f /src/loader
parent285b6f32c28d1cda403ba33bfb2d22c34fab2a1e (diff)
downloadchawan-ac3e737867245ac65adfa2352ce6e7fdacc57b18.tar.gz
buffer: simplify contentType handling
* remove contentType member of Buffer object
* add ishtml to reduce string comparisons
* consistent spelling: contenttype -> contentType
Diffstat (limited to 'src/loader')
-rw-r--r--src/loader/loader.nim4
-rw-r--r--src/loader/response.nim6
2 files changed, 5 insertions, 5 deletions
diff --git a/src/loader/loader.nim b/src/loader/loader.nim
index 6ab3ee9b..6cd17f44 100644
--- a/src/loader/loader.nim
+++ b/src/loader/loader.nim
@@ -312,10 +312,10 @@ proc applyHeaders(loader: FileLoader, request: Request, response: Response) =
     # it breaks mailcap named attributes other than charset.)
     # Ideally, contentType would be a separate object type.
     let header = response.headers.table["Content-Type"][0].toLowerAscii()
-    response.contenttype = header.until(';').strip().toLowerAscii()
+    response.contentType = header.until(';').strip().toLowerAscii()
     response.charset = getCharset(header.getAttribute("charset"))
   else:
-    response.contenttype = guessContentType($response.url.path,
+    response.contentType = guessContentType($response.url.path,
       "application/octet-stream", DefaultGuess)
   if "Location" in response.headers.table:
     if response.status in 301u16..303u16 or response.status in 307u16..308u16:
diff --git a/src/loader/response.nim b/src/loader/response.nim
index 1133a5e4..8ad98f84 100644
--- a/src/loader/response.nim
+++ b/src/loader/response.nim
@@ -17,7 +17,7 @@ type
     fd*: int
     body*: Stream
     bodyUsed* {.jsget.}: bool
-    contenttype*: string
+    contentType*: string
     status* {.jsget.}: uint16
     headers* {.jsget.}: Headers
     redirect*: Request
@@ -75,11 +75,11 @@ proc blob(response: Response): Promise[JSResult[Blob]] {.jsfunc.} =
   response.bodyRead = nil
   return bodyRead.then(proc(s: string): JSResult[Blob] =
     if s.len == 0:
-      return ok(newBlob(nil, 0, response.contenttype, nil))
+      return ok(newBlob(nil, 0, response.contentType, nil))
     GC_ref(s)
     let deallocFun = proc() =
       GC_unref(s)
-    let blob = newBlob(unsafeAddr s[0], s.len, response.contenttype, deallocFun)
+    let blob = newBlob(unsafeAddr s[0], s.len, response.contentType, deallocFun)
     ok(blob))
 
 proc json(ctx: JSContext, this: Response): Promise[JSResult[JSValue]]