I'm not an a rust expert, but I see that there are errors on the protocol level:
... CONNECT www.domain.com:443 HTTP/1.1
...
First, it should be
not
. More importantly, one must wait for the HTTP response of the proxy and only establish the TLS connection after one got the full response. Otherwise the plain HTTP response of the proxy will be interpreted as reply inside the TLS handshake and thus the handshake will fail. See also Wikipedia for a short example of this handshake.
... GET https://www.example.com/ HTTP/1.1
...
This is not a valid HTTP/1.1 request. It is missing at least the Host
header and the request line should only contain the path /
and not the full URL.
If you really want to implement HTTP yourself instead of using libraries, please study the actual standards instead of second-guessing how the protocol might work.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…