From 4464fc4e6eaa9b86e6e3c7b0cfdb960425cca0c4 Mon Sep 17 00:00:00 2001 From: Ryan Whitworth Date: Tue, 16 Jun 2015 23:32:23 -0400 Subject: [PATCH 1/8] handle RFC 2047 file names neither B or Q encoding --- lib/HTTP/Response.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/HTTP/Response.pm b/lib/HTTP/Response.pm index 928a11be..3838582d 100644 --- a/lib/HTTP/Response.pm +++ b/lib/HTTP/Response.pm @@ -149,6 +149,7 @@ sub filename $file = $encfile unless $@; } + else { return undef; } } } } From 5f33a64e3a14e64463771335e2b926088f9466eb Mon Sep 17 00:00:00 2001 From: Ryan Whitworth Date: Tue, 16 Jun 2015 23:37:53 -0400 Subject: [PATCH 2/8] Additional HTTP::Response test cases --- t/99resp.t | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 t/99resp.t diff --git a/t/99resp.t b/t/99resp.t new file mode 100644 index 00000000..f08c37b0 --- /dev/null +++ b/t/99resp.t @@ -0,0 +1,52 @@ +#!perl -w + +# Test extra HTTP::Response methods. Basic operation is tested in the +# message.t test suite and response.t test suite + +use strict; +use Test; +plan tests => 12; + +use HTTP::Date; +use HTTP::Request; +use HTTP::Response; + +my $time = time; + +my $req = HTTP::Request->new(GET => 'http://www.sn.no'); +my $r = new HTTP::Response 200, 'OK'; + +ok($r->is_redirect, ''); +ok($r->is_error, ''); +ok($r->is_client_error, ''); +ok($r->is_server_error, ''); +ok($r->is_info, ''); +ok($r->filename, undef); + +$r = new HTTP::Response 302, "Found"; +$r->request($req); +ok($r->is_redirect, 1); + +# basic header with an ascii filename defined +$r->push_header('Content-Disposition', 'attachment; filename="fname.ext"'); +ok($r->filename, 'fname.ext'); + +# incorrect header that has no filename defined +$r->remove_header('Content-Disposition'); +$r->push_header('Content-Disposition', 'attachment; q;'); +ok($r->filename, undef); + +# Q is quoted printable encoding type, filename() should return 'a' +$r->remove_header('Content-Disposition'); +$r->push_header('Content-Disposition', 'attachment; q; filename="=?ISO-8859-1?Q?a?="'); +ok($r->filename, 'a'); + +# B is base64 encoding type, filename() should return 'a' +$r->remove_header('Content-Disposition'); +$r->push_header('Content-Disposition', 'attachment; filename="=?ISO-8859-1?B?YQ=?="'); +ok($r->filename, 'a'); + +# K is not a valid encoding type, filename() should return undef +$r->remove_header('Content-Disposition'); +$r->push_header('Content-Disposition', 'attachment; q; filename="=?ISO-8859-1?K?YQ=?="'); +ok($r->filename, undef); From 683201ce0611f5fc49d2efc69a7317dc902ecc6d Mon Sep 17 00:00:00 2001 From: Ryan Whitworth Date: Tue, 16 Jun 2015 23:44:33 -0400 Subject: [PATCH 3/8] updated version --- lib/HTTP/Response.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/HTTP/Response.pm b/lib/HTTP/Response.pm index 3838582d..5e9593c3 100644 --- a/lib/HTTP/Response.pm +++ b/lib/HTTP/Response.pm @@ -2,7 +2,7 @@ package HTTP::Response; require HTTP::Message; @ISA = qw(HTTP::Message); -$VERSION = "6.04"; +$VERSION = "6.06"; use strict; use HTTP::Status (); From f971cd95c0e08985129c2a00edaac0a7a1896eb3 Mon Sep 17 00:00:00 2001 From: Ryan Whitworth Date: Tue, 16 Jun 2015 23:48:53 -0400 Subject: [PATCH 4/8] Updating invalid Content-Disposition response filename --- t/99resp.t | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/t/99resp.t b/t/99resp.t index f08c37b0..a80a2bc2 100644 --- a/t/99resp.t +++ b/t/99resp.t @@ -36,6 +36,11 @@ $r->remove_header('Content-Disposition'); $r->push_header('Content-Disposition', 'attachment; q;'); ok($r->filename, undef); +# incorrect header that has no filename defined, but does have a filename field +$r->remove_header('Content-Disposition'); +$r->push_header('Content-Disposition', 'attachment; q; filename=""'); +ok($r->filename, undef); + # Q is quoted printable encoding type, filename() should return 'a' $r->remove_header('Content-Disposition'); $r->push_header('Content-Disposition', 'attachment; q; filename="=?ISO-8859-1?Q?a?="'); From 516c39ab3f2972b65fcb80d59b735dd3dd2dab11 Mon Sep 17 00:00:00 2001 From: Ryan Whitworth Date: Wed, 17 Jun 2015 00:14:28 -0400 Subject: [PATCH 5/8] Update 99resp.t --- t/99resp.t | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/t/99resp.t b/t/99resp.t index a80a2bc2..479b27a2 100644 --- a/t/99resp.t +++ b/t/99resp.t @@ -5,7 +5,7 @@ use strict; use Test; -plan tests => 12; +plan tests => 13; use HTTP::Date; use HTTP::Request; @@ -33,17 +33,17 @@ ok($r->filename, 'fname.ext'); # incorrect header that has no filename defined $r->remove_header('Content-Disposition'); -$r->push_header('Content-Disposition', 'attachment; q;'); +$r->push_header('Content-Disposition', 'attachment;'); ok($r->filename, undef); # incorrect header that has no filename defined, but does have a filename field $r->remove_header('Content-Disposition'); -$r->push_header('Content-Disposition', 'attachment; q; filename=""'); +$r->push_header('Content-Disposition', 'attachment; filename=""'); ok($r->filename, undef); # Q is quoted printable encoding type, filename() should return 'a' $r->remove_header('Content-Disposition'); -$r->push_header('Content-Disposition', 'attachment; q; filename="=?ISO-8859-1?Q?a?="'); +$r->push_header('Content-Disposition', 'attachment; filename="=?ISO-8859-1?Q?a?="'); ok($r->filename, 'a'); # B is base64 encoding type, filename() should return 'a' @@ -53,5 +53,6 @@ ok($r->filename, 'a'); # K is not a valid encoding type, filename() should return undef $r->remove_header('Content-Disposition'); -$r->push_header('Content-Disposition', 'attachment; q; filename="=?ISO-8859-1?K?YQ=?="'); +$r->push_header('Content-Disposition', 'attachment; filename="=?ISO-8859-1?K?YQ=?="'); ok($r->filename, undef); + From 4c2596dc44dad644e2ba60d5e1157b2420d99a57 Mon Sep 17 00:00:00 2001 From: rwhitworth Date: Wed, 17 Jun 2015 12:50:33 -0400 Subject: [PATCH 6/8] fleshed out 1xx, 2xx, 3xx, 4xx, and 5xx series of tests --- t/99resp.t | 316 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 315 insertions(+), 1 deletion(-) diff --git a/t/99resp.t b/t/99resp.t index 479b27a2..eee6635a 100644 --- a/t/99resp.t +++ b/t/99resp.t @@ -5,7 +5,7 @@ use strict; use Test; -plan tests => 13; +plan tests => 89; use HTTP::Date; use HTTP::Request; @@ -23,10 +23,324 @@ ok($r->is_server_error, ''); ok($r->is_info, ''); ok($r->filename, undef); +$r = new HTTP::Response 100, "Continue"; +$r->request($req); +ok($r->is_info, 1); + +$r = new HTTP::Response 101, "Switching Protocols"; +$r->request($req); +ok($r->is_info, 1); + +$r = new HTTP::Response 102, "Processing"; +$r->request($req); +ok($r->is_info, 1); + + + +# is_success() for 2xx series of responses ... goes here. + +$r = new HTTP::Response 200, "OK"; +$r->request($req); +ok($r->is_success, 1); + +$r = new HTTP::Response 201, "Created"; +$r->request($req); +ok($r->is_success, 1); + +$r = new HTTP::Response 202, "Accepted"; +$r->request($req); +ok($r->is_success, 1); + +$r = new HTTP::Response 203, "Non-Authoritative Information"; +$r->request($req); +ok($r->is_success, 1); + +$r = new HTTP::Response 204, "No Content"; +$r->request($req); +ok($r->is_success, 1); + +$r = new HTTP::Response 205, "Reset Content"; +$r->request($req); +ok($r->is_success, 1); + +$r = new HTTP::Response 206, "Partial Content"; +$r->request($req); +ok($r->is_success, 1); + +$r = new HTTP::Response 207, "Multi-Status"; +$r->request($req); +ok($r->is_success, 1); + +$r = new HTTP::Response 208, "Already Reported"; +$r->request($req); +ok($r->is_success, 1); + +$r = new HTTP::Response 226, "IM Used"; +$r->request($req); +ok($r->is_success, 1); + + +$r = new HTTP::Response 300, "Multiple Choices"; +$r->request($req); +ok($r->is_redirect, 1); + +$r = new HTTP::Response 301, "Moved Permanently"; +$r->request($req); +ok($r->is_redirect, 1); + $r = new HTTP::Response 302, "Found"; $r->request($req); ok($r->is_redirect, 1); +$r = new HTTP::Response 303, "See Other"; +$r->request($req); +ok($r->is_redirect, 1); + +$r = new HTTP::Response 304, "Not Modified"; +$r->request($req); +ok($r->is_redirect, 1); + +$r = new HTTP::Response 305, "Use Proxy"; +$r->request($req); +ok($r->is_redirect, 1); + +$r = new HTTP::Response 306, "Switch Proxy"; +$r->request($req); +ok($r->is_redirect, 1); + +$r = new HTTP::Response 307, "Temporary Redirect"; +$r->request($req); +ok($r->is_redirect, 1); + +$r = new HTTP::Response 308, "Permanent Redirect"; +$r->request($req); +ok($r->is_redirect, 1); + + +$r = new HTTP::Response 400, "Bad Request"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 401, "Unauthorized"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 402, "Payment Required"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 403, "Forbidden"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 404, "Not Found"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 405, "Method Not Allowed"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 406, "Not Acceptable"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 407, "Proxy Authentication Required"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 408, "Request Timeout"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 409, "Conflict"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 410, "Gone"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 411, "Length Required"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 412, "Precondition Failed"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 413, "Request Entity Too Large"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 414, "Request-URI Too Long"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 415, "Unsupported Media Type"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 416, "Request Range Not Satisfiable"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 417, "Expectation Failed"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 418, "I'm a teapot"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 419, "Authentication Timeout"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 420, "Method Failure"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 421, "Misdirected Request"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 422, "Unprocessable Entity"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 423, "Locked"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 424, "Failed Dependency"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 428, "Precondition Required"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 429, "Too Many Requests"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 431, "Request Header Fields Too Large"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 440, "Login Timeout"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 444, "No Response"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 449, "Retry With"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 450, "Blocked by Windows Parental Controls"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 451, "Redirect"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 451, "Unavailable For Legal Reasons"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 494, "Request Header Too Large"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 495, "Cert Error"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 496, "No Cert"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 497, "HTTP to HTTPS"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 498, "Token expired/invalid"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 499, "Client Closed Request"; +$r->request($req); +ok($r->is_client_error, 1); + +$r = new HTTP::Response 499, "Token required"; +$r->request($req); +ok($r->is_client_error, 1); + + +$r = new HTTP::Response 500, "Internal Server Error"; +$r->request($req); +ok($r->is_server_error, 1); + +$r = new HTTP::Response 501, "Not Implemented"; +$r->request($req); +ok($r->is_server_error, 1); + +$r = new HTTP::Response 502, "Bad Gateway"; +$r->request($req); +ok($r->is_server_error, 1); + +$r = new HTTP::Response 503, "Service Unavailable"; +$r->request($req); +ok($r->is_server_error, 1); + +$r = new HTTP::Response 504, "Gateway Timeout"; +$r->request($req); +ok($r->is_server_error, 1); + +$r = new HTTP::Response 505, "HTTP Version Not Supported"; +$r->request($req); +ok($r->is_server_error, 1); + +$r = new HTTP::Response 506, "Variant Also Negotiates"; +$r->request($req); +ok($r->is_server_error, 1); + +$r = new HTTP::Response 507, "Insufficient Storage"; +$r->request($req); +ok($r->is_server_error, 1); + +$r = new HTTP::Response 508, "Loop Detected"; +$r->request($req); +ok($r->is_server_error, 1); + +$r = new HTTP::Response 509, "Bandwidth Limit Exceeded"; +$r->request($req); +ok($r->is_server_error, 1); + +$r = new HTTP::Response 510, "Not Extended"; +$r->request($req); +ok($r->is_server_error, 1); + +$r = new HTTP::Response 511, "Network Authentication Required"; +$r->request($req); +ok($r->is_server_error, 1); + +$r = new HTTP::Response 598, "Network read timeout error"; +$r->request($req); +ok($r->is_server_error, 1); + +$r = new HTTP::Response 599, "Network connect timeout error"; +$r->request($req); +ok($r->is_server_error, 1); + + + + # basic header with an ascii filename defined $r->push_header('Content-Disposition', 'attachment; filename="fname.ext"'); ok($r->filename, 'fname.ext'); From c6bd1db72c5a97a95ef8dcae8655cf51720f9c06 Mon Sep 17 00:00:00 2001 From: rwhitworth Date: Wed, 17 Jun 2015 22:15:46 -0400 Subject: [PATCH 7/8] additional tests --- t/99resp.t | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/t/99resp.t b/t/99resp.t index eee6635a..854a4967 100644 --- a/t/99resp.t +++ b/t/99resp.t @@ -5,7 +5,7 @@ use strict; use Test; -plan tests => 89; +plan tests => 94; use HTTP::Date; use HTTP::Request; @@ -15,6 +15,21 @@ my $time = time; my $req = HTTP::Request->new(GET => 'http://www.sn.no'); my $r = new HTTP::Response 200, 'OK'; +$r->push_header('Client-Date', 'Fri, 10 Dec 2010 15:20:02 GMT'); +ok($r->current_age, time() - 1291994402); +$r->push_header('Date', '2015-06-06'); +ok($r->current_age, time() - 1291994402); +$r->remove_header('Client-Date'); +ok($r->current_age, 0); +$r->push_header('Age', 1); +ok($r->current_age, 1); +$r->remove_header('Age'); +my $t_ime = time(); +$r->remove_header('Client-Date'); +$r->push_header('Age', $t_ime + $t_ime); +ok($r->current_age, $t_ime + $t_ime); +$r->remove_header('Age'); + ok($r->is_redirect, ''); ok($r->is_error, ''); From b57671e5a3b04deddf68d8dd373057e038f53a40 Mon Sep 17 00:00:00 2001 From: Ryan Whitworth Date: Sun, 4 Oct 2015 14:35:07 -0400 Subject: [PATCH 8/8] Update Response.pm --- lib/HTTP/Response.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/HTTP/Response.pm b/lib/HTTP/Response.pm index 5e9593c3..3838582d 100644 --- a/lib/HTTP/Response.pm +++ b/lib/HTTP/Response.pm @@ -2,7 +2,7 @@ package HTTP::Response; require HTTP::Message; @ISA = qw(HTTP::Message); -$VERSION = "6.06"; +$VERSION = "6.04"; use strict; use HTTP::Status ();