From ea6406f4b8da40e669076d24cbba090bc77cd9bf Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Tue, 19 Sep 2017 14:09:47 +0200 Subject: [PATCH] Compute response's Content-Length once --- lib/nanoserve.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/nanoserve.rb b/lib/nanoserve.rb index 3ed9bfa..0b761eb 100644 --- a/lib/nanoserve.rb +++ b/lib/nanoserve.rb @@ -186,7 +186,7 @@ module NanoServe end def body=(value) - @body = value.tap { @content_length = body.bytes.count.to_s } + @body = value.tap { @content_length = value.bytes.count.to_s } end def to_s @@ -216,7 +216,7 @@ module NanoServe end def content_length - @content_length ||= body.bytes.count.to_s + @content_length || '0' end def content_type