Skip to content

Commit

Permalink
use more Content-Length headers again
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 12, 2015
1 parent c0c7a93 commit 139938c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
3 changes: 1 addition & 2 deletions Changes
@@ -1,8 +1,7 @@

6.15 2015-08-12
- Removed deprecated build_body and build_headers methods from Mojo::Content.
- Improved Mojo::Message and Mojo::Transaction::HTTP to generate slightly
smaller HTTP messages.
- Improved Mojo::Transaction::HTTP performance slightly.
- Fixed warnings in Mojo::DOM.

6.14 2015-07-12
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Message.pm
Expand Up @@ -99,8 +99,8 @@ sub fix_headers {
my $headers = $content->headers;
if ($content->is_multipart) { $headers->remove('Content-Length') }
elsif ($content->is_chunked || $headers->content_length) { return $self }
if ($content->is_dynamic) { $headers->connection('close') }
elsif (my $size = $self->body_size) { $headers->content_length($size) }
if ($content->is_dynamic) { $headers->connection('close') }
else { $headers->content_length($self->body_size) }

return $self;
}
Expand Down
4 changes: 4 additions & 0 deletions t/mojo/request.t
Expand Up @@ -1248,6 +1248,7 @@ is $req->url->to_abs, 'http://example.com/demo', 'right absolute URL';
is $req->headers->connection, 'Upgrade', 'right "Connection" value';
is $req->headers->upgrade, 'websocket', 'right "Upgrade" value';
is $req->headers->host, 'example.com', 'right "Host" value';
is $req->headers->content_length, 0, 'right "Content-Length" value';
is $req->headers->sec_websocket_accept, 'abcdef=',
'right "Sec-WebSocket-Key" value';
is $req->headers->sec_websocket_protocol, 'sample',
Expand Down Expand Up @@ -1275,6 +1276,7 @@ is $req->url->to_abs, 'http://example.com/demo', 'right absolute URL';
is $req->headers->connection, 'Upgrade', 'right "Connection" value';
is $req->headers->upgrade, 'websocket', 'right "Upgrade" value';
is $req->headers->host, 'example.com', 'right "Host" value';
is $req->headers->content_length, 0, 'right "Content-Length" value';
is $req->headers->sec_websocket_accept, 'abcdef=',
'right "Sec-WebSocket-Key" value';
is $req->headers->sec_websocket_protocol, 'sample',
Expand All @@ -1290,6 +1292,7 @@ is $clone->url->to_abs, 'http://example.com/demo', 'right absolute URL';
is $clone->headers->connection, 'Upgrade', 'right "Connection" value';
is $clone->headers->upgrade, 'websocket', 'right "Upgrade" value';
is $clone->headers->host, 'example.com', 'right "Host" value';
is $req->headers->content_length, 0, 'right "Content-Length" value';
is $clone->headers->sec_websocket_accept, 'abcdef=',
'right "Sec-WebSocket-Key" value';
is $clone->headers->sec_websocket_protocol, 'sample',
Expand All @@ -1316,6 +1319,7 @@ is $req->url->to_abs, 'http://example.com/demo', 'right absolute URL';
is $req->headers->connection, 'Upgrade', 'right "Connection" value';
is $req->headers->upgrade, 'websocket', 'right "Upgrade" value';
is $req->headers->host, 'example.com', 'right "Host" value';
is $req->headers->content_length, 0, 'right "Content-Length" value';
is $req->headers->sec_websocket_accept, 'abcdef=',
'right "Sec-WebSocket-Key" value';
is $req->headers->sec_websocket_protocol, 'sample',
Expand Down
6 changes: 5 additions & 1 deletion t/mojo/response.t
Expand Up @@ -671,6 +671,7 @@ is $res->code, '404', 'right status';
is $res->message, 'Not Found', 'right message';
is $res->version, '1.1', 'right version';
is $res->headers->date, 'Sun, 17 Aug 2008 16:27:35 GMT', 'right "Date" value';
is $res->headers->content_length, 0, 'right "Content-Length" value';

# Build HTTP 1.1 response start-line with minimal headers (strange message)
$res = Mojo::Message::Response->new;
Expand All @@ -683,6 +684,7 @@ is $res->code, '404', 'right status';
is $res->message, 'Looks-0k!@ ;\':" #$%^<>,.\\o/ &*()', 'right message';
is $res->version, '1.1', 'right version';
is $res->headers->date, 'Sun, 17 Aug 2008 16:27:35 GMT', 'right "Date" value';
is $res->headers->content_length, 0, 'right "Content-Length" value';

# Build HTTP 1.1 response start-line and header
$res = Mojo::Message::Response->new;
Expand Down Expand Up @@ -876,7 +878,8 @@ is $res->message, 'Switching Protocols', 'right message';
is $res->version, '1.1', 'right version';
is $res->headers->connection, 'Upgrade', 'right "Connection" value';
is $res->headers->date, 'Sun, 17 Aug 2008 16:27:35 GMT', 'right "Date" value';
is $res->headers->upgrade, 'websocket', 'right "Upgrade" value';
is $res->headers->content_length, 0, 'right "Content-Length" value';
is $res->headers->upgrade, 'websocket', 'right "Upgrade" value';
is $res->headers->sec_websocket_accept, 'abcdef=',
'right "Sec-WebSocket-Accept" value';
is $res->headers->sec_websocket_protocol, 'sample',
Expand All @@ -898,6 +901,7 @@ $res2->parse($res->to_string);
ok $res2->is_finished, 'response is finished';
is $res2->code, 404, 'right status';
is $res2->version, '1.1', 'right version';
is $res2->headers->content_length, 0, 'right "Content-Length" value';
ok defined $res2->cookie('foo'), 'cookie "foo" exists';
ok defined $res2->cookie('bar'), 'cookie "bar" exists';
ok defined $res2->cookie('baz'), 'cookie "baz" exists';
Expand Down

0 comments on commit 139938c

Please sign in to comment.