New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mojo::UserAgent is unable to make HTTPS requests via a proxy #468
Comments
This is not a bug, you can't perform HTTPS requests through an HTTP proxy without CONNECT. |
If so, why does it work with LWP::UserAgent? I use the same HTTP proxy in that test case. In the Mojo::UA debugging error stream I can see Squid complaining that CONNECT is not permitted. |
Only you can find that out, perhaps it's using a SOCKS proxy instead. |
Ok thanks. |
After some further investigation, I think there is an issue here. Firstly, I made a mistake: my proxy server does support CONNECT. Sorry for the confusion. These are the request/response headers sent/received between Mojo::UA and the proxy:.
Note that the Host header is set to the proxy IP, instead of the remote host. I think this is not right. If I force the Host header like this: use Mojo::UserAgent;
use Data::Dump;
my $ua = Mojo::UserAgent->new;
$ua->on(start => sub {
my ($ua, $tx) = @_;
$tx->req->headers->remove('Host')->add(Host => 'www.google.co.uk');
});
$ua->https_proxy('http://xxxxxx:xxxxxx@xx.xx.xx.xx:xxxx');
dd $ua->get('https://www.google.co.uk/')->error;
dd $ua->get('https://www.google.co.uk/')->res->body; The connection is successful:
However, no data is sent or received over then connection. I think the TLS handshake does not complete. For reference, this is how Firefox does it:
and this is how LWP::UserAgent does it (note that LWP::UA does not perform end-to-end TLS using CONNECT):
|
Yes, it looks like it may be a problem in Mojolicious to me. The |
Thanks, should be fixed. |
The CONNECT is now being established. But then the client immediately closes the connection. use Mojo::UserAgent;
my $ua = Mojo::UserAgent->new;
$ua->https_proxy($http_proxy);
print $ua->get('https://www.google.co.uk/')->res->body; Running with MOJO_USERAGENT_DEBUG=1 produces this:
In Wireshark I can see the next packet sent is a FIN from the client, instead of inializing SSL. I have the latest IO::Socket::SSL (1.84). If you would like to try, here is a fast public HTTP proxy that I have been using for tests. I can't give my private proxy here but I can share over email.
How can I debug this further? Thanks. |
Thanks, this was a rather odd bug, it should be fixed now, but i'm not sure yet how to test it. |
I can confirm it is fixed for me. Mojolicious support is truly awesome. Thank you! |
And it's also tested now, so this shouldn't happen again. 0a591b3 |
Printing the request methods inside a start event, Mojo::UserAgent appears to make 2 requests: first a GET, and then a CONNECT. However, only the CONNECT is reported when debugging output is enabled.
I can make HTTPS requests through the proxy using Firefox or LWP::UserAgent, which makes me think there is something wrong with Mojo::UserAgent.
Test code using Mojo::UserAgent:
Output:
The equivalent using LWP::UserAgent:
Output:
The text was updated successfully, but these errors were encountered: