bridgetownrb / bridgetown

A next-generation progressive site generator & fullstack framework, powered by Ruby
https://www.bridgetownrb.com
MIT License
1.13k stars 114 forks source link

404 error page is served with wrong Content-Type header #341

Closed wolfgangrittner closed 2 years ago

wolfgangrittner commented 3 years ago

Bridgetown Version: 0.21.0

To Reproduce

Current behavior

If the 404.html page contains any non-escaped special characters (example: German umlauts, like ü or ä), they are not displayed correctly. The Content-Type response header for the 404 response is content-type: text/html; charset=ISO-8859-1.

Expected behavior

Any special characters are displayed correctly, and the 404 response is served using the same content-type and encoding as any other response. In my case, and that's the default as far as I know, I'd expect content-type: "text/html; charset=UTF-8".

Screenshots

Bildschirmfoto 2021-06-23 um 16 11 24

(instead of "zurück zur Startseite")

Computing environment (please complete the following information):

Additional context

I suspect the culprit is this line here: https://github.com/bridgetownrb/bridgetown/blob/main/bridgetown-core/lib/bridgetown-core/commands/serve.rb#L93 When serving the 404 response, it tries to set a Content-Type header (title cased), but there's already a content-type header (lower case) present, which seems to take precedence.

I believe I've a fix for this already, would be happy to provide a PR if that's cool?

jaredcwhite commented 3 years ago

Thanks for the details on this. We're actually in the process of removing Webrick and switching to a Rack-based server infrastructure, so I wouldn't bother trying to patch what's there now. I'll leave this issue open though so we can double-check the new system fixes the problem.

jaredcwhite commented 2 years ago

I can't seem to repro with the new Puma/Rack server…and on Ruby 3 at least I can't even repro with Webrick either (returns a UTF-8 charset). Closing.