Skip to content

Commit

Permalink
added experimental stream api to Mojo::IOLoop and fixed finish event …
Browse files Browse the repository at this point in the history
…timing in Mojo::Server::Daemon
  • Loading branch information
kraih committed Oct 27, 2011
1 parent ea49fed commit a90c401
Show file tree
Hide file tree
Showing 24 changed files with 375 additions and 228 deletions.
11 changes: 11 additions & 0 deletions Changes
@@ -1,5 +1,16 @@
This file documents the revision history for Perl extension Mojolicious.

2.12 2011-10-27 00:00:00
- Added EXPERIMENTAL cleanup_interval attribute to Mojo::IOLoop.
- Added EXPERIMENTAL max_leftover_size attribute to Mojo::Content.
- Replaced handle method in Mojo::IOLoop with stream method.
- Replaced writing and not_writing methods in Mojo::IOWatcher with
watch method.
- Replaced is_finished method in Mojo::IOLoop::Stream with is_writing
method.
- Reduced memory usage of Mojo::Headers significantly.
- Fixed finish event timing in Mojo::Server::Daemon.

2.11 2011-10-26 00:00:00
- Improved Mojo::IOLoop::Stream to only emit close events once.
- Improved documentation.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Asset/Memory.pm
Expand Up @@ -91,7 +91,7 @@ implements the following new ones.
Maximum asset size in bytes, only attempt upgrading to a L<Mojo::Asset::File>
object after reaching this limit, defaults to the value of
C<MOJO_MAX_MEMORY_SIZE> or C<5262144>.
C<MOJO_MAX_MEMORY_SIZE> or C<262144>.
Note that this attribute is EXPERIMENTAL and might change without warning!
=head1 METHODS
Expand Down
30 changes: 15 additions & 15 deletions lib/Mojo/Content.pm
Expand Up @@ -8,6 +8,7 @@ use constant CHUNK_SIZE => $ENV{MOJO_CHUNK_SIZE} || 131072;

has [qw/auto_relax relaxed/] => 0;
has headers => sub { Mojo::Headers->new };
has max_leftover_size => sub { $ENV{MOJO_MAX_LEFTOVER_SIZE} || 262144 };

sub body_contains {
croak 'Method "body_contains" not implemented by subclass';
Expand Down Expand Up @@ -110,10 +111,7 @@ sub get_header_chunk {
return substr $self->{header_buffer}, $offset, CHUNK_SIZE;
}

sub has_leftovers {
my $self = shift;
return length($self->{buffer}) || length($self->{pre_buffer});
}
sub has_leftovers { length(shift->{buffer} || '') }

sub header_size { length shift->build_headers }

Expand All @@ -138,16 +136,7 @@ sub is_multipart {undef}

sub is_parsing_body { (shift->{state} || '') eq 'body' }

sub leftovers {
my $self = shift;

# Chunked leftovers are in the chunked buffer, and so are those from a
# HEAD request
return $self->{pre_buffer} if length $self->{pre_buffer};

# Normal leftovers
return $self->{buffer};
}
sub leftovers { shift->{buffer} }

# DEPRECATED in Smiling Face With Sunglasses!
sub on_read {
Expand Down Expand Up @@ -186,7 +175,9 @@ sub parse {
# Not chunked, pass through to second buffer
else {
$self->{real_size} += length $self->{pre_buffer};
$self->{buffer} .= $self->{pre_buffer};
$self->{buffer} .= $self->{pre_buffer}
unless $self->is_finished
&& length($self->{buffer}) > $self->max_leftover_size;
$self->{pre_buffer} = '';
}

Expand Down Expand Up @@ -476,6 +467,15 @@ Try to detect broken web servers and turn on relaxed parsing automatically.
Content headers, defaults to a L<Mojo::Headers> object.
=head2 C<max_leftover_size>
my $size = $content->max_leftover_size;
$content = $content->max_leftover_size(1024);
Maximum size in bytes of buffer for pipelined HTTP requests, defaults to the
value of C<MOJO_MAX_LEFTOVER_SIZE> or C<262144>.
Note that this attribute is EXPERIMENTAL and might change without warning!
=head2 C<relaxed>
my $relaxed = $content->relaxed;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/EventEmitter.pm
Expand Up @@ -29,8 +29,8 @@ sub once {
my $wrapper;
$wrapper = sub {
my $self = shift;
$self->$cb(@_);
$self->unsubscribe($name => $wrapper);
$self->$cb(@_);
};
$self->on($name => $wrapper);
weaken $wrapper;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Headers.pm
Expand Up @@ -180,7 +180,7 @@ sub is_limit_exceeded { shift->{limit} }

sub last_modified { scalar shift->header('Last-Modified' => @_) }

sub leftovers { shift->{buffer} }
sub leftovers { delete shift->{buffer} }

sub location { scalar shift->header(Location => @_) }

Expand Down

0 comments on commit a90c401

Please sign in to comment.