Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with calling callback after write data to client with content_length header #949

Closed
Logioniz opened this issue Apr 28, 2016 · 4 comments
Labels

Comments

@Logioniz
Copy link

In accordance with the documentation, I believe that callback should be called always. But when you set the content_length header, then the last callback is not invoked. Below is the test that shows this behavior.

#!/usr/bin/perl
use Mojolicious::Lite;
use Test::Mojo;
use Test::More;

get '/' => sub {
  my $c = shift->render_later;
  $c->res->headers->content_length(2);
  $c->write('11', sub { app->defaults(qwe => 1234); $c->finish });
};

app->start;

my $t = Test::Mojo->new;
$t->get_ok('/')->status_is(200);
is app->defaults('qwe'), 1234;

done_testing;

I believe that this is a bug, since it's not documented.

@kraih kraih added the bug label Apr 28, 2016
@kraih
Copy link
Member

kraih commented Apr 28, 2016

Looks like a bug.

@anparker
Copy link
Contributor

anparker commented Apr 29, 2016

Documentation for write says it write dynamic content, but if you set content_length, content does not treated as dynamic any more.

https://metacpan.org/source/SRI/Mojolicious-6.60/lib/Mojo/Content.pm#L62

I disabled check for content_length in this line and test above passed. But I don't think, that is a solution.

@anparker
Copy link
Contributor

https://metacpan.org/source/SRI/Mojolicious-6.60/lib/Mojo/Transaction/HTTP.pm#L66

Here, when all needed data has been send, transaction is marked as completed. And get_body_chunk will never be called again. That's only place, where drain event for Mojo::Content emitted.

http://pastebin.com/HTN1WXE2

This thing worked, but it looks more like workaround.

@kraih kraih closed this as completed in 6ab2acc Apr 30, 2016
@kraih
Copy link
Member

kraih commented Apr 30, 2016

Thanks, should be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants