Skip to content

Commit

Permalink
added experimental support for new HTTP status codes from draft-notti…
Browse files Browse the repository at this point in the history
…ngham-http-new-status
  • Loading branch information
kraih committed Oct 20, 2011
1 parent aa6a838 commit 0376afa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,6 +1,8 @@
This file documents the revision history for Perl extension Mojolicious.

2.03 2011-10-20 00:00:00
- Added EXPERIMETNAL support for new HTTP status codes from
draft-nottingham-http-new-status.
- Improved documentation.
- Fixed small bug in "upload_lite_app.t".

Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/Message.pm
Expand Up @@ -291,7 +291,7 @@ sub is_dynamic { shift->content->is_dynamic }
sub is_limit_exceeded {
my $self = shift;
return unless my $code = ($self->error)[1];
return unless $code eq '413';
return unless $code ~~ [413, 431];
return 1;
}

Expand Down Expand Up @@ -429,7 +429,7 @@ sub _parse {
# Check line size
my $len = index $self->{buffer}, "\x0a";
$len = length $self->{buffer} if $len < 0;
return $self->error('Maximum line size exceeded.', 413)
return $self->error('Maximum line size exceeded.', 431)
if $len > $self->max_line_size;

# Parse
Expand Down Expand Up @@ -459,7 +459,7 @@ sub _parse {
}

# Check line size
return $self->error('Maximum line size exceeded.', 413)
return $self->error('Maximum line size exceeded.', 431)
if $self->headers->is_limit_exceeded;

# Done
Expand Down
8 changes: 6 additions & 2 deletions lib/Mojo/Message/Response.pm
Expand Up @@ -18,7 +18,7 @@ my $START_LINE_RE = qr/
$
/x;

# Umarked codes are from RFC 2616 (mostly taken from LWP)
# Umarked codes are from RFC 2616
my %MESSAGES = (
100 => 'Continue',
101 => 'Switching Protocols',
Expand Down Expand Up @@ -62,6 +62,9 @@ my %MESSAGES = (
424 => 'Failed Dependency', # RFC 2518 (WebDAV)
425 => 'Unordered Colection', # RFC 3648 (WebDav)
426 => 'Upgrade Required', # RFC 2817
428 => 'Precondition Required', # draft-nottingham-http-new-status
429 => 'Too Many Requests', # draft-nottingham-http-new-status
431 => 'Request Header Fields Too Large', # draft-nottingham-http-new-status
449 => 'Retry With', # unofficial Microsoft
500 => 'Internal Server Error',
501 => 'Not Implemented',
Expand All @@ -72,7 +75,8 @@ my %MESSAGES = (
506 => 'Variant Also Negotiates', # RFC 2295
507 => 'Insufficient Storage', # RFC 2518 (WebDAV)
509 => 'Bandwidth Limit Exceeded', # unofficial
510 => 'Not Extended' # RFC 2774
510 => 'Not Extended', # RFC 2774
511 => 'Network Authentication Required', # draft-nottingham-http-new-status
);

sub cookies {
Expand Down
11 changes: 8 additions & 3 deletions t/mojo/message.t
Expand Up @@ -3,7 +3,7 @@ use Mojo::Base -strict;

use utf8;

use Test::More tests => 1258;
use Test::More tests => 1263;

use File::Spec;
use File::Temp;
Expand Down Expand Up @@ -248,7 +248,8 @@ $ENV{MOJO_MAX_LINE_SIZE} = 5;
$req->parse('GET /foo/bar/baz.html HTTP/1');
ok $req->is_done, 'request is done';
is(($req->error)[0], 'Maximum line size exceeded.', 'right error');
is(($req->error)[1], 413, 'right status');
is(($req->error)[1], 431, 'right status');
is $req->is_limit_exceeded, 1, 'limit is exceeded';
$ENV{MOJO_MAX_LINE_SIZE} = $backup;

# Parse HTTP 1.0 start line and headers (with line size limit)
Expand All @@ -259,7 +260,8 @@ $req->parse("GET / HTTP/1.0\x0d\x0a");
$req->parse("Content-Type: text/plain\x0d\x0a");
ok $req->is_done, 'request is done';
is(($req->error)[0], 'Maximum line size exceeded.', 'right error');
is(($req->error)[1], 413, 'right status');
is(($req->error)[1], 431, 'right status');
is $req->is_limit_exceeded, 1, 'limit is exceeded';
$ENV{MOJO_MAX_LINE_SIZE} = $backup;

# Parse HTTP 1.0 start line (with message size limit)
Expand All @@ -270,6 +272,7 @@ $req->parse('GET /foo/bar/baz.html HTTP/1');
ok $req->is_done, 'request is done';
is(($req->error)[0], 'Maximum message size exceeded.', 'right error');
is(($req->error)[1], 413, 'right status');
is $req->is_limit_exceeded, 1, 'limit is exceeded';
$ENV{MOJO_MAX_MESSAGE_SIZE} = $backup;

# Parse HTTP 1.0 start line and headers (with message size limit)
Expand All @@ -281,6 +284,7 @@ $req->parse("Content-Type: text/plain\x0d\x0a");
ok $req->is_done, 'request is done';
is(($req->error)[0], 'Maximum message size exceeded.', 'right error');
is(($req->error)[1], 413, 'right status');
is $req->is_limit_exceeded, 1, 'limit is exceeded';
$ENV{MOJO_MAX_MESSAGE_SIZE} = $backup;

# Parse HTTP 1.0 start line, headers and body (with message size limit)
Expand All @@ -294,6 +298,7 @@ $req->parse('Hello World!');
ok $req->is_done, 'request is done';
is(($req->error)[0], 'Maximum message size exceeded.', 'right error');
is(($req->error)[1], 413, 'right status');
is $req->is_limit_exceeded, 1, 'limit is exceeded';
$ENV{MOJO_MAX_MESSAGE_SIZE} = $backup;

# Parse full HTTP 1.0 request
Expand Down

0 comments on commit 0376afa

Please sign in to comment.