my ($domain) = $i =~ m/@(.*).cookies$/;
# print STDERR "Cookie bag for domian $domain found ";
if ($host =~ m/$domain$/) { # If the domain of the cookie bag tail matches the host, it is
applicable
# print STDERR "which *does* need to be sent.\n";
my $filehandle;
if (open ($filehandle,$i)) {
while (<$filehandle>) {
chomp $_;
# print STDERR " Found: $_\n";
# print STDERR "Time: $curtime\n";
my %cookiehash = parseStoredCookie($_);
# print STDERR "Path restriction: $cookiehash{'path'}\n";
if ($url =~ m/^$cookiehash{'path'}/i) { # if the cookie's path head matches the path of
the script it should be sent
# print STDERR " which should be sent.\n\n";
if ((not $cookiehash{'expiresEpoch'}) or ($cookiehash{'expiresEpoch'} >= time)) { # Don't
use expired cookies
$cookies2send[$#cookies2send+1] = {%cookiehash}; # We're going to store the cookies we
want to send here so we can sort them before we send them.
}
} else {
# print STDERR " which should not be sent.\n\n";
}
}
close $filehandle;
# print STDERR "\n";
} else {
print STDERR sortableDate() . " Tried to open cookie bag $i and failed.\n Error: $!\n\n";
}
} else {
# print STDERR "which does not need to be sent.\n\n";
}
}
# foreach $i (@cookies2send) {
# print STDERR " $i: $$i{'name'} = $$i{'value'} ($$i{'domain'} $$i{'path'})
($$i{'expires'} $$i{'expiresEpoch'})\n";
# }
# print STDERR "\n\n";
@cookies2send = sort {length($$b{'path'}) <=> length($$a{'path'}) || length($$b{'domain'}) <=>
length($$a{'domain'})} @cookies2send; # cookies with more specific paths, or more specific domains
if the paths are the same should go first - longer names are more specific names
# foreach $i (@cookies2send) {
# print STDERR " $i: $$i{'name'} = $$i{'value'} ($$i{'domain'} $$i{'path'})
($$i{'expires'} $$i{'expiresEpoch'})\n";
# }
my $cookieString = '';
if (defined $cookies2send[0]) {
$cookieString = join('=',($cookies2send[0]{'name'},$cookies2send[0]{'value'}));
}
for ($i=1; $i <= $#cookies2send; $i++) {
$cookieString .= '; ' . join('=',($cookies2send[$i]{'name'},$cookies2send[$i]{'value'}));
}
if ($cookieString) {
$$headers{'cookie'} = $cookieString;
logevent ($user,$$headers{'x-forwarded-for'},"Host:
$$self{'_hphf_proxy'}{'request'}{'_headers'}{'host'}\tCookie\t$cookieString") if $logDetail;
say("Give cookie: $cookieString\n",9);
} else {
# Don't send any cookies but the ones we track (dump cookies provided by browser if any)
delete $$headers{'cookie'};
logevent ($user,$$headers{'x-forwarded-for'},"Host:
$$self{'_hphf_proxy'}{'request'}{'_headers'}{'host'}\tCookie Note\tNo cookies to give.") if
$logDetail;
# print STDERR "No cookies to give.\n";
}
}
}
}
);
# The response header filter that follows handles receiving cookies from the
# web server and storing them to be sent with later requests.
my $responseHeaderFilter = HTTP::Proxy::HeaderFilter::simple->new(
sub {
my ( $self, $headers, $message) = @_;
say ("MIME: $$headers{'content-type'}\n",4);
my ($hop, $i, $j, $cookiename, $value);
my $uri = scalar($$message{'_request'}{'_uri'});
my ($protocol, $hoststring, $url, $params) = $uri =~ m/([^:]*):\/\/([^\/]*)(\/[^?]*)?(\?.*)?/;
if ($HoTTProxyConfig{'ProxyCookiesEnabled'}) {
foreach $i (sort(keys(%{$headers}))) {
if (lc($i) eq 'set-cookie') {
my @headerList = ();
if (ref($$headers{$i})) {
@headerList = @{$$headers{$i}};
} else {
@headerList = ($$headers{$i});
=5= |