rack icon indicating copy to clipboard operation
rack copied to clipboard

Runtime in Server-Timing header

Open lewispb opened this issue 5 months ago • 4 comments

Server-Timing is the standard way to report server performance to the user agent nowadays. I like that it's standardized around reporting milliseconds, and this is presented meaningfully in web browsers dev tools.

This PR introduces Rack::ServerTiming to set (or append to) the Server-Timing response header, with a duration measurement value, similar to the existing Rack::Runtime middleware.

lewispb avatar Oct 09 '25 13:10 lewispb

I can't think of a situation where I'd want both headers, one with seconds and one with milliseconds.

That's fair. Happy to split this out into Rack::ServerTiming.

this overrides an existing server-timing header

I don't think my implementation does, does it?

lewispb avatar Oct 09 '25 15:10 lewispb

this overrides an existing server-timing header

I don't think my implementation does, does it?

No, it doesn't, sorry about that.

jeremyevans avatar Oct 09 '25 16:10 jeremyevans

Thanks for your initial review @jeremyevans. I've addressed it with a new Rack::ServerTiming middleware here.

lewispb avatar Oct 09 '25 20:10 lewispb

It looks like the external test failure is unrelated.

Failure message
  1) Rack::Sendfile when calling sendfile contains Sendfile headers
     Failure/Error: expect(headers).to include('X-Accel-Redirect')
       expected {"cache-control" => "no-cache", "content-type" => "application/json"} to include "X-Accel-Redirect"
       Diff:
       @@ -1 +1,2 @@
       -["X-Accel-Redirect"]
       +"cache-control" => "no-cache",
       +"content-type" => "application/json",
     # ./spec/grape/integration/rack_sendfile_spec.rb:34:in `block (3 levels) in <top (required)>'

lewispb avatar Oct 13 '25 09:10 lewispb