Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 30, 2010
1 parent 721d9b8 commit 29b3447
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 36 deletions.
44 changes: 9 additions & 35 deletions lib/Mojo/Content.pm
Expand Up @@ -15,8 +15,7 @@ __PACKAGE__->attr('read_cb');
__PACKAGE__->attr([qw/buffer chunked_buffer/] => sub { Mojo::ByteStream->new }
);
__PACKAGE__->attr(headers => sub { Mojo::Headers->new });
__PACKAGE__->attr(raw_header_size => 0);
__PACKAGE__->attr(relaxed => 0);
__PACKAGE__->attr(relaxed => 0);

sub body_contains {
croak 'Method "body_contains" not implemented by subclass';
Expand Down Expand Up @@ -201,7 +200,9 @@ sub parse {
}

# Done
$self->{_state} = 'done' if $length <= $self->raw_body_size;
$self->{_state} = 'done'
if $length <= $self->chunked_buffer->raw_size
- ($self->{_header_size} || 0);
}
}

Expand All @@ -228,17 +229,14 @@ sub parse_until_body {
my ($self, $chunk) = @_;

# Buffer
my $fbuffer = $self->chunked_buffer;
$fbuffer->add_chunk($chunk);
my $buffer = $self->chunked_buffer;
$buffer->add_chunk($chunk);

# Parser started
unless ($self->{_state}) {

# Update size
my $length = $fbuffer->size;
my $raw_length = $fbuffer->raw_size;
my $raw_header_length = $raw_length - $length;
$self->raw_header_size($raw_header_length);
$self->{_header_size} = $buffer->raw_size - $buffer->size;

# Headers
$self->{_state} = 'headers';
Expand All @@ -250,15 +248,6 @@ sub parse_until_body {
return $self;
}

sub raw_body_size {
my $self = shift;

# Calculate
my $length = $self->chunked_buffer->raw_size;
my $header_length = $self->raw_header_size;
return $length - $header_length;
}

sub write {
my ($self, $chunk, $cb) = @_;

Expand Down Expand Up @@ -407,11 +396,8 @@ sub _parse_headers {
$headers->parse;

# Update size
my $buffer = $headers->buffer;
my $length = $buffer->size;
my $raw_length = $buffer->raw_size;
my $raw_header_length = $raw_length - $length;
$self->raw_header_size($raw_header_length);
my $buffer = $headers->buffer;
$self->{_header_size} = $buffer->raw_size - $buffer->size;

# Done
$self->{_state} = 'body' if $headers->is_done;
Expand Down Expand Up @@ -479,12 +465,6 @@ Note that this attribute is EXPERIMENTAL and might change without warning!
Activate relaxed parsing for HTTP 0.9.
=head2 C<raw_header_size>
my $size = $content->raw_header_size;
Raw size of headers in bytes.
=head1 METHODS
L<Mojo::Content> inherits all methods from L<Mojo::Base> and implements the
Expand Down Expand Up @@ -607,12 +587,6 @@ Parse body once.
Parse and stop after headers.
=head2 C<raw_body_size>
my $size = $content->raw_body_size;
Raw size of body in bytes.
=head2 C<write>
$content->write('Hello!');
Expand Down
4 changes: 3 additions & 1 deletion lib/Mojo/Content/Single.pm
Expand Up @@ -92,7 +92,9 @@ sub parse {
$asset->add_chunk($self->buffer->remove($need)) if $need > 0;

# Done
$self->{_state} = 'done' if $length <= $self->raw_body_size;
$self->{_state} = 'done'
if $length <= $self->chunked_buffer->raw_size
- ($self->{_header_size} || 0);
}

return $self;
Expand Down

0 comments on commit 29b3447

Please sign in to comment.