8

I want to return a HTTP 204 error code if anyone tries to access a particular path on my web server. I could set one of my webservers to return a 204 error and point haproxy to it as a backend. However since no information is being sent, I figured this should be possible to do from haproxy itself. No need to bother my actual web servers.

I tried creating a backend that would generate the 204 error as follows:

frontend ...
    ...
    acl is_always204 path_beg /thisone
    use_backend always204 if is_always204
    ...

backend always204
    errorfile 404 /etc/haproxy-shared/errors/204.http

The 204.http file contains:

HTTP/1.0 204 No Content Cache-Control: no-cache Connection: close Content-Type: image/png

When I start haproxy, I get this error:

parsing [/etc/haproxy/haproxy:51] : status code 404 not handled, error customization will be ignored.

I think I may be going about this the wrong way. Can anyone suggest a way to force haproxy to return a 204 for a given acl match?

TomOnTime
  • 7,945
  • 6
  • 32
  • 52
  • 2
    Have you tried making this the `503` errorfile? There are no actual backend servers, so HAproxy should serve the `503` response. – Felix Frank Sep 14 '14 at 12:47
  • Do you think that a 204 is the correct status code for this situation? According to the [HAProxy](http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#errorfile) documentation, 204 and 404 are not supported return codes. It seems like this might want to [return a 403](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html). 204 suggests that the request was delivered to the server. – Anthony Fammartino Nov 15 '14 at 23:38
  • 1
    Interesting. `Content-Type` makes no sense in this context, but there really isn't enough information here to figure out what the context is. Of course HTTP 204 is rarely used anyway. My feeling about 204 is that the origin server should probably be sending it, if there is a scenario where using it makes sense at all. – Michael Hampton Nov 16 '14 at 01:07

1 Answers1

2

As mentioned in the comments, you cannot specify an errorfile for 404, as HAProxy will never generate a 404. You must use something like 503, which HAProxy does actually emit and has a configurable error file. Your 204 file can be used as is, just substitute 503 for 204 in your config.

dglloyd
  • 171
  • 5