1use Test::More skip_all => "Can't make this work with Crypt::SSLeay"; 2use strict; 3use t::Utils; 4use HTTP::Proxy; 5use LWP::UserAgent; 6 7# test CONNECT 8my $test = Test::Builder->new; 9 10# this is to work around tests in forked processes 11$test->use_numbers(0); 12$test->no_ending(1); 13 14SKIP: { 15 eval "require Crypt::SSLeay;" 16 skip "Crypt::SSLeay not installed", 1 if $@; 17 18my $proxy = HTTP::Proxy->new( port => 0, maxconn => 1, logmask => 63 ); 19 20# Excerpts from the Crypt::SSLeay documentation 21# --------------------------------------------- 22# LWP::UserAgent and Crypt::SSLeay have their own versions of proxy support. 23# 24# At the time of this writing, libwww v5.6 seems to proxy https requests 25# fine with an Apache mod_proxy server. It sends a line like: 26# 27# GET https://www.nodeworks.com HTTP/1.1 28# 29# to the proxy server, which is not the CONNECT request that some 30# proxies would expect, so this may not work with other proxy servers 31# than mod_proxy. The CONNECT method is used by Crypt::SSLeay's internal 32# proxy support. 33# 34# For native Crypt::SSLeay proxy support of https requests, you need to 35# set an environment variable HTTPS_PROXY to your proxy server & port, as in: 36# 37# # PROXY SUPPORT 38# $ENV{HTTPS_PROXY} = 'http://proxy_hostname_or_ip:port'; 39# $ENV{HTTPS_PROXY} = '127.0.0.1:8080'; 40# 41# Use of the HTTPS_PROXY environment variable in this way is similar to 42# LWP::UserAgent->env_proxy() usage, but calling that method will likely 43# override or break the Crypt::SSLeay support, so do not mix the two. 44 45#$proxy->agent( LWP::UserAgent->new ); # no env_proxy 46$proxy->init; # required to access the url later 47 48# fork a HTTP proxy 49my $pid = fork_proxy( 50 $proxy, 51 sub { 52 ok( $proxy->conn == 1, 53 "Served the correct number of requests" ); 54 } 55); 56 57# run a client 58my $ua = LWP::UserAgent->new; # no env_proxy 59$ENV{HTTPS_PROXY} = $proxy->url; # to be used by Crypt::SSLeay 60#$ENV{HTTPS_DEBUG} = 1; 61 62my $req = HTTP::Request->new( GET => "https://www.gandi.net/"); 63my $res = $ua->request($req); 64#print $res->status_line,$/,$res->headers->as_string; #500 ?? 65 66# make sure the kid is dead 67wait; 68 69} 70 71# tests with lwp-request: 72# HTTPS_PROXY=http://localhost:8080/ \ 73# HTTPS_DEBUG=1 \ 74# lwp-request -P -des https://www.nodeworks.com/ 75# 76# -P prevents lwp-request to call env_proxy() on its agent, 77# so that Crypt::SSLeay can use the HTTPS_PROXY environment variable 78 79