Skip to content

Commit

Permalink
Add ServerTiming headers for TimeData Collector
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh authored Feb 15, 2017
1 parent 0718804 commit 9d5c0f1
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/LaravelDebugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,8 @@ public function modifyResponse(Request $request, Response $response)
}
}

$this->addServerTimingHeaders($response);

return $response;
}

Expand Down Expand Up @@ -906,4 +908,23 @@ protected function addClockworkHeaders(Response $response)
$response->headers->set('X-Clockwork-Version', 1, true);
$response->headers->set('X-Clockwork-Path', $prefix .'/clockwork/', true);
}

/**
* Add Server-Timing headers for the TimeData collector
*
* @see https://www.w3.org/TR/server-timing/
* @param Response $response
*/
protected function addServerTimingHeaders(Response $response)
{
if ($this->hasCollector('time')) {
$collector = $this->getCollector('time');

foreach ($collector->collect()['measures'] as $k => $m) {
$headers[] = sprintf('%d=%F; "%s"', $k, $m['duration'], str_replace('"', "'", $m['label']));
}

$response->headers->set('Server-Timing', $collector->getServerTimingHeaders(), false);
}
}
}

0 comments on commit 9d5c0f1

Please sign in to comment.