From 33e95075d97801884192e1d460f4ee3f1ee56e07 Mon Sep 17 00:00:00 2001 From: PikachuEXE Date: Mon, 5 Mar 2018 16:33:58 +0800 Subject: [PATCH] * Update header value format to be "Chrome parsable" --- lib/server_timing/timing_metric.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/server_timing/timing_metric.rb b/lib/server_timing/timing_metric.rb index ecfd045..2b07935 100644 --- a/lib/server_timing/timing_metric.rb +++ b/lib/server_timing/timing_metric.rb @@ -18,12 +18,17 @@ def initialize(name,duration, description: nil) end def to_header - "#{name}; dur=#{duration.to_d.truncate(2).to_f}; #{description_to_header}" + "#{name}=#{duration.to_d.truncate(2).to_f} #{description_to_header}" end + # For description the "quoted string" must be using double quotes + # as specified in + # https://www.w3.org/TR/server-timing/#the-server-timing-header-field + # + # Also semicolon should only be added if is additional filed to add def description_to_header return unless description - "desc='#{description}';" + "; \"#{description}\"" end end -end \ No newline at end of file +end