SWI-Prolog / packages-http

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

http_reply_from_files gives an error on Linux #160

Closed Brikaa closed 1 year ago

Brikaa commented 1 year ago

When using http_reply_from_files with a file specified in the URL on Linux, it gives a permission error. This is because http_safe_file is called on PathInfo which has a leading slash; making it think it is an absolute path. The reason this works on Windows is probably because absolute file paths do not start with leading slashes.

JanWielemaker commented 1 year ago

The handler must be defined on an HTTP location that ends in a /. Then the path info does not contain the leading /. This works well if you use http:location/3 to define virtual paths and then define the handler on alias(.). If you do not use the alias mechanism you need e.g., http_handler('/files/', ...

I don't really see how drive letters end up there. They shouldn't.

Brikaa commented 1 year ago

Thanks, that was the problem. This leads to inconsistent behavior between Windows and Linux though when there is no trailing backslash in the code. But I am not sure if that would be the code author's problem or a problem that should be handled here.

JanWielemaker commented 1 year ago

Should probably be documented explicitly.