mirror of
https://github.com/mirror/wget.git
synced 2025-01-16 07:10:23 +08:00
Heed cookies from 401s.
This commit is contained in:
parent
57c9e17e6c
commit
d21dde51b8
@ -1,3 +1,9 @@
|
||||
2009-08-27 Micah Cowan <micah@cowan.name>
|
||||
|
||||
* http.c (gethttp): Make sure Wget heeds cookies when they
|
||||
are sent with a 401 response; or any other sort of response for
|
||||
that matter (#26775).
|
||||
|
||||
2009-08-19 Micah Cowan <micah@cowan.name>
|
||||
|
||||
* openssl.c (ssl_check_certificate): Only warn about an attack if
|
||||
|
36
src/http.c
36
src/http.c
@ -1871,6 +1871,24 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy,
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle (possibly multiple instances of) the Set-Cookie header. */
|
||||
if (opt.cookies)
|
||||
{
|
||||
int scpos;
|
||||
const char *scbeg, *scend;
|
||||
/* The jar should have been created by now. */
|
||||
assert (wget_cookie_jar != NULL);
|
||||
for (scpos = 0;
|
||||
(scpos = resp_header_locate (resp, "Set-Cookie", scpos,
|
||||
&scbeg, &scend)) != -1;
|
||||
++scpos)
|
||||
{
|
||||
char *set_cookie; BOUNDED_TO_ALLOCA (scbeg, scend, set_cookie);
|
||||
cookie_handle_set_cookie (wget_cookie_jar, u->host, u->port,
|
||||
u->path, set_cookie);
|
||||
}
|
||||
}
|
||||
|
||||
if (keep_alive)
|
||||
/* The server has promised that it will not close the connection
|
||||
when we're done. This means that we can register it. */
|
||||
@ -2099,24 +2117,6 @@ File %s already there; not retrieving.\n\n"), quote (hs->local_file));
|
||||
hs->newloc = resp_header_strdup (resp, "Location");
|
||||
hs->remote_time = resp_header_strdup (resp, "Last-Modified");
|
||||
|
||||
/* Handle (possibly multiple instances of) the Set-Cookie header. */
|
||||
if (opt.cookies)
|
||||
{
|
||||
int scpos;
|
||||
const char *scbeg, *scend;
|
||||
/* The jar should have been created by now. */
|
||||
assert (wget_cookie_jar != NULL);
|
||||
for (scpos = 0;
|
||||
(scpos = resp_header_locate (resp, "Set-Cookie", scpos,
|
||||
&scbeg, &scend)) != -1;
|
||||
++scpos)
|
||||
{
|
||||
char *set_cookie; BOUNDED_TO_ALLOCA (scbeg, scend, set_cookie);
|
||||
cookie_handle_set_cookie (wget_cookie_jar, u->host, u->port,
|
||||
u->path, set_cookie);
|
||||
}
|
||||
}
|
||||
|
||||
if (resp_header_copy (resp, "Content-Range", hdrval, sizeof (hdrval)))
|
||||
{
|
||||
wgint first_byte_pos, last_byte_pos, entity_length;
|
||||
|
@ -1,3 +1,18 @@
|
||||
2009-08-27 Micah Cowan <micah@cowan.name>
|
||||
|
||||
* run-px: Added Test-cookies.px, Test-cookies-401.px
|
||||
|
||||
* Test-cookies.px: Basic testing to make sure Wget doesn't send
|
||||
cookies; no path/domain checking.
|
||||
|
||||
* Test-cookies.px: Test to make sure Wget heeds cookies when they
|
||||
are sent with a 401 response (#26775).
|
||||
|
||||
* HTTPServer.pm (send_response): Don't try to substitute port in
|
||||
response body, if there isn't one.
|
||||
(verify_request_headers): Avoid uninitialized warning when an
|
||||
expected header isn't provided by Wget.
|
||||
|
||||
2009-07-27 Micah Cowan <micah@cowan.name>
|
||||
|
||||
* Test-restrict-ascii.px: New.
|
||||
|
@ -123,7 +123,7 @@ sub send_response {
|
||||
next;
|
||||
}
|
||||
# fill in content
|
||||
$content = $self->_substitute_port($content);
|
||||
$content = $self->_substitute_port($content) if defined $content;
|
||||
$resp->content($content);
|
||||
print STDERR "HTTP::Response with content: \n", $resp->as_string if $log;
|
||||
}
|
||||
@ -221,6 +221,7 @@ sub verify_request_headers {
|
||||
my $rhdr = $req->header ($hdrname);
|
||||
my $ehdr = $url_rec->{'request_headers'}{$hdrname};
|
||||
unless (defined $rhdr && $rhdr =~ $ehdr) {
|
||||
$rhdr = '' unless defined $rhdr;
|
||||
print STDERR "\n*** Mismatch on $hdrname: $rhdr =~ $ehdr\n";
|
||||
return undef;
|
||||
}
|
||||
|
53
tests/Test-cookies-401.px
Executable file
53
tests/Test-cookies-401.px
Executable file
@ -0,0 +1,53 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use HTTPTest;
|
||||
|
||||
|
||||
###############################################################################
|
||||
|
||||
my $content = "You got it.\n";
|
||||
|
||||
# code, msg, headers, content
|
||||
my %urls = (
|
||||
'/one.txt' => {
|
||||
code => "401",
|
||||
msg => "Forbidden",
|
||||
headers => {
|
||||
"Set-Cookie" => "foo=bar",
|
||||
},
|
||||
},
|
||||
'/two.txt' => {
|
||||
code => "200",
|
||||
msg => "Ok",
|
||||
content => $content,
|
||||
request_headers => {
|
||||
"Cookie" => qr|foo=bar|,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
my $cmdline = $WgetTest::WGETPATH . " -d http://localhost:{{port}}/one.txt"
|
||||
. " http://localhost:{{port}}/two.txt";
|
||||
|
||||
my $expected_error_code = 0;
|
||||
|
||||
my %expected_downloaded_files = (
|
||||
'two.txt' => {
|
||||
content => $content,
|
||||
},
|
||||
);
|
||||
|
||||
###############################################################################
|
||||
|
||||
my $the_test = HTTPTest->new (name => "Test-cookies-401",
|
||||
input => \%urls,
|
||||
cmdline => $cmdline,
|
||||
errcode => $expected_error_code,
|
||||
output => \%expected_downloaded_files);
|
||||
exit $the_test->run();
|
||||
|
||||
# vim: et ts=4 sw=4
|
||||
|
59
tests/Test-cookies.px
Executable file
59
tests/Test-cookies.px
Executable file
@ -0,0 +1,59 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use HTTPTest;
|
||||
|
||||
|
||||
###############################################################################
|
||||
|
||||
my $page1 = "Hello, world!\n";
|
||||
my $page2 = "Goodbye, Sam.\n";
|
||||
|
||||
# code, msg, headers, content
|
||||
my %urls = (
|
||||
'/one.txt' => {
|
||||
code => "200",
|
||||
msg => "Ok",
|
||||
headers => {
|
||||
"Content-type" => "text/plain",
|
||||
"Set-Cookie" => "foo=bar",
|
||||
},
|
||||
content => $page1,
|
||||
},
|
||||
'/two.txt' => {
|
||||
code => "200",
|
||||
msg => "Ok",
|
||||
content => $page2,
|
||||
request_headers => {
|
||||
"Cookie" => qr|foo=bar|,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
my $cmdline = $WgetTest::WGETPATH . " http://localhost:{{port}}/one.txt"
|
||||
. " http://localhost:{{port}}/two.txt";
|
||||
|
||||
my $expected_error_code = 0;
|
||||
|
||||
my %expected_downloaded_files = (
|
||||
'one.txt' => {
|
||||
content => $page1,
|
||||
},
|
||||
'two.txt' => {
|
||||
content => $page2,
|
||||
},
|
||||
);
|
||||
|
||||
###############################################################################
|
||||
|
||||
my $the_test = HTTPTest->new (name => "Test-cookies",
|
||||
input => \%urls,
|
||||
cmdline => $cmdline,
|
||||
errcode => $expected_error_code,
|
||||
output => \%expected_downloaded_files);
|
||||
exit $the_test->run();
|
||||
|
||||
# vim: et ts=4 sw=4
|
||||
|
@ -14,6 +14,8 @@ my @tests = (
|
||||
'Test-auth-basic.px',
|
||||
'Test-auth-no-challenge.px',
|
||||
'Test-auth-no-challenge-url.px',
|
||||
'Test-cookies.px',
|
||||
'Test-cookies-401.px',
|
||||
'Test-proxy-auth-basic.px',
|
||||
'Test-proxied-https-auth.px',
|
||||
'Test-N-HTTP-Content-Disposition.px',
|
||||
|
Loading…
Reference in New Issue
Block a user