about summary refs log tree commit diff stats
path: root/src/loader/response.nim
diff options
context:
space:
mode:
Diffstat (limited to 'src/loader/response.nim')
-rw-r--r--src/loader/response.nim10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/loader/response.nim b/src/loader/response.nim
index 2be709c7..92aa5c7a 100644
--- a/src/loader/response.nim
+++ b/src/loader/response.nim
@@ -65,14 +65,14 @@ proc text*(response: Response): Promise[JSResult[string]] {.jsfunc.} =
   let bodyRead = response.bodyRead
   response.bodyRead = nil
   return bodyRead.then(proc(s: string): JSResult[string] =
-    if response.charset == CHARSET_UTF_8 and s.validateUtf8() == -1:
+    let cs = if response.charset == CHARSET_UNKNOWN:
+      CHARSET_UTF_8
+    else:
+      response.charset
+    if cs == CHARSET_UTF_8 and s.validateUtf8() == -1:
       ok(s)
     else:
       let ss = newStringStream(s)
-      let cs = if response.charset == CHARSET_UNKNOWN:
-        CHARSET_UTF_8
-      else:
-        response.charset
       let ds = newDecoderStream(ss, cs)
       let es = newEncoderStream(ds, CHARSET_UTF_8)
       return ok(es.readAll())