From e05dfde3fbb5128497066cbe1359eaec0e5e6b90 Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Wed, 8 Feb 2017 17:52:13 -0700 Subject: [PATCH] Content-Length: handle body w/ UTF8 characters for Ruby 1.9+ to avoid Rack::Lint::LintError --- lib/load_speed.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/load_speed.rb b/lib/load_speed.rb index c36b5c5..6930241 100644 --- a/lib/load_speed.rb +++ b/lib/load_speed.rb @@ -14,7 +14,10 @@ def call(env) index = body.rindex("") if index body.insert(index, performance_code) - headers["Content-Length"] = body.length.to_s + # + # handle body w/ UTF8 characters for Ruby 1.9+ to avoid Rack::Lint::LintError + # + headers["Content-Length"] = (body.respond_to?(:bytesize) ? body.bytesize : body.length).to_s response = [body] end end