From 93a32258cb6a99b967ec4d0c2ea0349b75396e74 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Thu, 31 May 2018 14:18:24 -0400 Subject: [PATCH 1/1] nitcorn: HttpResponse::body is now an agnostic Writable The only quirk is computing the length :( Signed-off-by: Jean Privat --- lib/nitcorn/http_response.nit | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/nitcorn/http_response.nit b/lib/nitcorn/http_response.nit index b80fb7b..97276ca 100644 --- a/lib/nitcorn/http_response.nit +++ b/lib/nitcorn/http_response.nit @@ -39,7 +39,7 @@ class HttpResponse var header = new HashMap[String, String] # Body of this response - var body = "" is writable + var body: Writable = "" is writable # Files appended after `body` var files = new Array[String] @@ -50,7 +50,20 @@ class HttpResponse # Set the content length if not already set if not header.keys.has("Content-Length") then # Size of the body - var len = body.byte_length + var len + var body = self.body + if body isa Text then + len = body.byte_length + else if body isa Bytes then + len = body.length + else + # We need the length, but there is no length in a writable. + # So just render it as a bytes then measure :/ + body = body.write_to_bytes + len = body.length + # Keep the body as bytes since we have it + self.body = body + end # Size of included files for path in files do -- 1.7.9.5