caddy: handle_errors 200 empty body

I think I found kind of an odd bug. I am using caddy as a static file server for a SPA, so if I get an error, I just want it to try again at the root directory – mostly for index.html and favicon

this works, returns index page but the status is still 404 on the successful document, odd but ok looking at the docs seems to be by design?

handle_errors {
  rewrite * /
  file_server
}

This one however – it works on the initial page load, but if you refresh the page it returns an empty body for the page request and the index.html file for the favicon

handle_errors {
  rewrite * /
  file_server {
    status 200
  }
}

initial page load: image image

page refresh: image

when doing a hard refresh you again get the correct response

I am assuming this is a bug with some kind of caching key mechanism in handle_errors?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 28 (14 by maintainers)

Most upvoted comments

@odama626 It is a simple example. And it generally works because people aren’t going to images directly, the web app is loading them as page subresources instead, and it wouldn’t be loading images that don’t exist (right??).

Anyway, I think more specific configs can be left as an exercise for the reader; it’s not feasible for us to give all possible examples… is it? Your specific requirements are likely not the next person’s.

yeah after trying it again that does seem to work, sorry I must have done something wrong before

that seems to still return the index.html for images and favicon

Not according to my tests and definitely doesn’t match the handler matching criteria. Favicons and images come with an extension, which won’t pass the regex. Plus, favicons are requested as example.com/favicon.ico (or .png) or by the alternative URL defined in the respective HTML tag (https://stackoverflow.com/a/35625707).

I honestly doubt you’re running the same config. Show evidence of debug logs and curl -v.