unit icon indicating copy to clipboard operation
unit copied to clipboard

PHP: Better error handling (403, 404 etc)

Open ac000 opened this issue 2 years ago • 0 comments

Currently the unit php module returns either a 500 'Internal Service Error' or 503 'Service Unavailable' in various scenarios.

E.g trying to access a directory that doesn't exist (or doesn't allow access)

$ curl -v http://[::1]:8080/bat/
*   Trying ::1:8080...
* Connected to ::1 (::1) port 8080 (#0)
> GET /bat/ HTTP/1.1
> Host: [::1]:8080
> User-Agent: curl/7.82.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 500 Internal Server Error
< X-Powered-By: PHP/8.1.10
< Content-type: text/html; charset=UTF-8
< Server: Unit/1.29.0
< Date: Wed, 05 Oct 2022 10:31:24 GMT
< Transfer-Encoding: chunked

This also allows us to fix one of the tests (test_php_application_targets() in test/test_php_targets.py)

        assert self.get(url='/1')['body'] == '1'
        assert self.get(url='/2')['body'] == '2'
>       assert self.get(url='/blah')['status'] == 503  # TODO 404
E       assert 404 == 503
E         +404
E         -503

We now return a 404 as expected.

ac000 avatar Oct 05 '22 10:10 ac000