Guss
Guss

Reputation: 32335

Using Rack::Static, no Content-Type header is sent

I'm using Rack::Static (or Rack::TryStatic) to serve some static HTML, Javascript, CSS and image files as part of a Rack application, but I see that the files served by Rack::Static do not have a Content-Type header, which causes warnings in some use cases and actually breaks the behavior of other use cases.

All the files have correct extensions, but the Content-Type header is actually missing from the HTTP response. I'm running Rack using Rackup which starts a WEBRick server.

How can I get Rack::Static to set up the correct content-type when sending files?

Upvotes: 0

Views: 421

Answers (1)

Bob Schultz
Bob Schultz

Reputation: 146

I know this is an old post, but I just had this same problem and I hoped that the solution might help someone. Try this:

use Rack::Static, urls: {'/my-doc' => '/public/my-doc'},
                  header_rules: [
                      ['/public/my-doc', {'Content-Type' => 'application/json'}]
                  ]

Upvotes: 1

Related Questions