c-cube / tiny_httpd

Minimal HTTP server using good old threads + blocking IO, with a small request router.
https://c-cube.github.io/tiny_httpd
75 stars 11 forks source link

Firefox hang on 301 redirect with no body #62

Closed craff closed 1 year ago

craff commented 1 year ago

The spec for http 301 seems to require a body (not clear) and firefox (but not chrome) will hang in this case. This affect redirection to index.html in directory managment.

Possible fix:

c-cube commented 1 year ago

Hmm I can't find anything in the specs about that. Do you have a way to reproduce the issue?

craff commented 1 year ago

Hello,

Do a make_void ~code:301, the response has no content length and no body and firefox (but no chrome hangs)

More precisely, to reproduce:

Line 252: S.Response.make_void ~code:301 ~headers:S.Headers.(empty |> set "location" new_path) ()

Then answer will have no body nor content-length and firefox will hang. No sure it is a bug as it will only happends if the user use the current interface to produce an answer with no body and no content-length.

Apparently only 1xx, 204 and 304 are allowed no body. Which in reality means that content_length must be present for all answer (even if zero) for code other thant 1xx, 204 and 304, if there is no Transfer-encoding in the header.

A fix, if you consider it is a bug, is to ensure to have always a content-length or transfer-encoding for code other than 1xx, 204 and 304.

Cheers, Christophe

Simon Cruanes writes:

Hmm I can't find anything in the specs about that. Do you have a way to reproduce the issue?

-- Christophe Raffalli tél: +689 87 23 11 48 web: http://raffalli.eu

Ce mail est signé avec pgp (Pièce jointe signature.asc, clef sur https://raffalli.eu/pgp) This mail is signed pgp (Attachment signature.asc, clef on https://raffalli.eu/pgp)