Hello list, the 401 is one of the http status code haproxy generates itself:
https://github.com/haproxy/haproxy/blob/v2.1.0/doc/configuration.txt#L363
This cannot however be overwritten using the errorfile keyword as stated in the
doc:
https://github.com/haproxy/haproxy/blob/v2.1.0/doc/configuration.txt#L3558
and also testing myself:
[WARNING] 142/002731 (1) : parsing [/tmp/haproxy/h.cfg:9] : status code 401
not
handled by 'errorfile', error customization will be ignored.
I'm aware that a Lua script can generate a custom page and an arbitrary http
status code which could work around this:
core.register_service("send-401", "http", function(applet)
send(applet, 401, [[
<html><body>My custom 401 page</body></html>
]])
end)
... but is there a way to, instead, customize the output of `http-request auth`?
Config:
$ cat h.cfg
defaults
timeout client 1s
timeout server 1s
timeout connect 1s
mode http
listen l
bind :8000
http-request auth if { always_true }
errorfile 401 /tmp/haproxy/401.http
server l 10.0.0.10:8000
Output:
$ curl -i localhost:8000 --user a:b
HTTP/1.1 401 Unauthorized
content-length: 112
cache-control: no-cache
content-type: text/html
www-authenticate: Basic realm=“l"
connection: close
<html><body><h1>401 Unauthorized</h1>
You need a valid user and password to access this content.
</body></html>
~jm