tarampampam / error-pages

🚧 Pretty server's error pages in the docker image & git repository (for traefik, k8s, nginx and so on)
https://tarampampam.github.io/error-pages/
MIT License
833 stars 81 forks source link

HTTP status code not set per code template #193

Closed jinnatar closed 1 year ago

jinnatar commented 1 year ago

Is there an existing issue for this?

Describe the bug

Fetching a specific error with /403.html (and anything not 404) returns as HTTP/1.1 200 OK but with the correct template content. Instead fetching / with a X-Code: 403 works as expected.

Steps to reproduce

  1. docker run --rm -it -p 1234:8080 ghcr.io/tarampampam/error-pages:2.24
  2. curl -v -H "X-Code: 403" localhost:1234 > /dev/null -> < HTTP/1.1 403 Forbidden
  3. curl -v localhost:1234/403.html > /dev/null -> < HTTP/1.1 200 OK

Configuration files

N/A, defaults are used.

Relevant log output

{"level":"info","ts":1682500829.970848,"msg":"We will use the requested template","name":"ghost"}
{"level":"info","ts":1682500829.971214,"msg":"Server starting","addr":"0.0.0.0","port":8080,"default error page":"404","default HTTP response code":404,"proxy headers":[],"show request details":false,"localization disabled":false}
{"level":"info","ts":1682500852.084728,"msg":"HTTP request processed","useragent":"''","method":"GET","url":"/403.html","referer":"","status_code":200,"content_type":"text/html; charset=utf-8","connection_close":false,"duration":0.000796617,"request_headers":["Host: localhost:1234","User-Agent: ''","Accept: */*"],"response_headers":["Content-Type: text/html; charset=utf-8","X-Robots-Tag: noindex"]}
{"level":"info","ts":1682500968.6593013,"msg":"HTTP request processed","useragent":"''","method":"GET","url":"/","referer":"","status_code":403,"content_type":"text/html; charset=utf-8","connection_close":false,"duration":0.000545044,"request_headers":["Host: localhost:1234","User-Agent: ''","Accept: */*","X-Code: 403"],"response_headers":["Content-Type: text/html; charset=utf-8","X-Robots-Tag: noindex"]}

Anything else?

No response

tarampampam commented 1 year ago

Hi @Artanicus! Why did you decide this is an error? For example, traefik expect 200 code (as I remember) to serve the error page content

jinnatar commented 1 year ago

From my previous tests with plain nginx responders, Traefik seemed to pass the error service response code to the client as-is, which breaks monitoring as everything seems like 200. Let me double check the repro via Traefik.

jinnatar commented 1 year ago

I can confirm that Traefik functions as you expected, i.e. it expects a 200 from the service but still emits the correct status to the end user. My bad!