Thats correct behavior: the browser requests a ressource, the server emits a 401 Unauthorized response so that the browser knows HTTP authentication is required, it will then ask the user for username and password and resend the HTTP requests with this data.
And how are you testing exactly and what behavior are you seeing?
Right now the only information you provided is that it is not working and that you get a 401 response.
To help you, you will have to provide more informations, I also suggest you share the full configuration and a full trace of curl -vv http://username:password@site/
Haproxy is primarily a reverse proxy, not a forward proxy.
I suggest you use an actual forward proxy instead, likey tinyproxy. Bending haproxy to your will for a use-case that is was not designed will result in a mess.