beast: Trying to connect to proxy returns wrong status code
Using Boost version 1.76 I’m not able to get authenticated HTTPS async client connection working through a proxy. After some debugging, it looks like the status code is returned incorrectly in my on_read callback. Even though the buffer clearly contains a 401 the error code will be 200. I’m a bit guessing, but it seems like the http parser does not like the but also does not provide an alternative error code (like internal error). I’ve tested with a Squid Proxy and a Nginx proxy.
The buffer contains the following data:
"HTTP/1.1 401 Unauthorized\r\nServer: nginx/1.11.9\r\nDate: Tue, 16 Nov 2021 02:58:30 GMT\r\nContent-Type: text/html\r\nContent-Length: 195\r\nConnection: keep-alive\r\nWWW-Authenticate: Basic realm=\"Restricted\"\r\n\r\n<html>\r\n<head><title>401 Authorization Required</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>401 Authorization Required</h1></center>\r\n<hr><center>nginx/1.11.9</center>\r\n</body>\r\n</html>\r\n"
For testing agains Nginx reverse proxy I was simply using the following minimalistic setup (https://github.com/dtan4/nginx-basic-auth-proxy):
docker run \
--rm \
--name nginx-basic-auth-proxy \
-p 8080:80 \
-p 8090:8090 \
-e BASIC_AUTH_USERNAME=username \
-e BASIC_AUTH_PASSWORD=password \
-e PROXY_PASS=https://www.google.com \
-e SERVER_NAME=proxy.dtan4.net \
-e PORT=80 \
quay.io/dtan4/nginx-basic-auth-proxy
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 21 (8 by maintainers)
Thanks! That was it indeed.
The last info is quite valuable. All examples I found were using empty_body (like https://stackoverflow.com/questions/69713739/how-to-connect-with-boostasio-to-a-https-server-using-a-proxy/69715628#69715628). Which made kind of sense for proxying.
if
ecindicates an error, the contents of the parsed response are unspecified (@madmongo1 the documentation should make this clear)