SWI-Prolog / packages-http

The SWI-Prolog HTTP server and client libraries
23 stars 23 forks source link

ENHANCED: Issue#142: http_reply_from_files/3: Return 301 Moved Permanently on directories without trailing / #143

Closed ntgiwsvp closed 4 years ago

ntgiwsvp commented 4 years ago

Dear Jan,

I stumbled over the issue now described as #142 a while ago when using http_reply_from_files/3. I investigated in the Discourse group, but it seems nobody else has encountered this yet. So I just went ahead and fixed it by copying the relevant code from http_reply_dirindex/3 to http_reply_from_files/3.

I was not able to get exactly the background for having both path and path_info members in the Request. In the examples I looked at the difference was that path includes a leading / while path_info does not. The redirect needs to include the leading / since otherwise it would be interpreted relative, so also extracted the path from the Request and propagated to locate_file as RequestPath. Since locate_file is not exported from the module I believe this cannot have any side effects.

Best regards Thomas

JanWielemaker commented 4 years ago

Thanks Thomas. I have reorganized the code a bit more, mostly as I did not like exceptions from the code finding how to respond. Kept you author. Don't worry about the conflict, this is merged.