--- lib\TWiki\Net.pm Mon Dec 03 10:50:06 2001 +++ lib\TWiki\Net.pm Wed Jan 23 00:35:46 2002 @@ -28,6 +28,9 @@ use strict; +# RNF 22 Jan 2002 For basic HTTP authentication. +use MIME::Base64; + use vars qw( $useSocket $useNetSmtp $mailInitialized $mailHost $helloHost @@ -42,7 +45,8 @@ # ========================= sub getUrl { - my ( $theHost, $thePort, $theUrl, $theHeader ) = @_; + my ( $theHost, $thePort, $theUrl, $theUser, $thePass, $theHeader ) = @_; + my $base64; if( ! $useSocket ) { use Socket; @@ -55,7 +59,15 @@ $theHeader = ""; } my $result = ''; - my $req = "GET $theUrl HTTP/1.0\r\n$theHeader\r\n\r\n"; + my $req = "GET $theUrl HTTP/1.0\r\n"; + + # RNF 22 Jan 2002 Support for vhosts and user authentication. + $req .= "Host: $theHost\r\n"; + if( $theUser && $thePass ) { + $base64 = encode_base64("$theUser:$thePass", "\r\n"); + $req .= "Authorization: Basic $base64"; + } + $req .= "$theHeader\r\n\r\n"; my ( $iaddr, $paddr, $proto ); $iaddr = inet_aton( $theHost ); $paddr = sockaddr_in( $thePort, $iaddr ); @@ -66,7 +78,7 @@ } unless( connect( SOCK, $paddr ) ) { &TWiki::writeWarning( "TWiki::Net::getUrl connect: $!" ); - return "content-type: text/plain\n\nERROR: TWiki::Net::getUrl connect: $!"; + return "content-type: text/plain\n\nERROR: TWiki::Net::getUrl connect: $!\n$req"; } select SOCK; $| = 1; print SOCK $req;