don't force an extra layer of streaming as doing so bypasses plack middlewares.
This commit is contained in:
parent
423e19ae0e
commit
742db182e8
2 changed files with 31 additions and 23 deletions
|
|
@ -68,23 +68,37 @@ sub call {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $env = shift;
|
my $env = shift;
|
||||||
|
|
||||||
# Use the PSGI callback style response, which allows for nice things like
|
my $session = $env->{'webgui.session'}
|
||||||
# delayed response/streaming body (server push). For now we just use this for
|
or die 'Missing WebGUI Session - check WebGUI::Middleware::Session';
|
||||||
# unbuffered response writing
|
|
||||||
return sub {
|
|
||||||
my $responder = shift;
|
|
||||||
my $session = $env->{'webgui.session'}
|
|
||||||
or die 'Missing WebGUI Session - check WebGUI::Middleware::Session';
|
|
||||||
|
|
||||||
# Handle the request
|
# Handle the request
|
||||||
$self->handle($session);
|
|
||||||
|
|
||||||
# Construct the PSGI response
|
$self->handle($session);
|
||||||
my $response = $session->response;
|
|
||||||
my $psgi_response = $response->finalize;
|
my $response = $session->response;
|
||||||
|
my $psgi_response = $response->finalize;
|
||||||
|
|
||||||
|
if ( ! $response->streaming ) {
|
||||||
|
|
||||||
|
# Not streaming, so immediately tell the callback to return
|
||||||
|
# the response. In the future we could use an Event framework here
|
||||||
|
# to make this a non-blocking delayed response.
|
||||||
|
|
||||||
|
return $psgi_response;
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
# Use the PSGI callback style response, which allows for nice things like
|
||||||
|
# delayed response/streaming body (server push).
|
||||||
|
# Delayed response prevents any nice MiddleWare::StackTrace-like modules from
|
||||||
|
# engaging so minimal error handling is done here.
|
||||||
|
|
||||||
|
return sub {
|
||||||
|
my $responder = shift;
|
||||||
|
|
||||||
|
# Construct the PSGI response
|
||||||
|
|
||||||
# See if the content handler is doing unbuffered response writing
|
|
||||||
if ( $response->streaming ) {
|
|
||||||
try {
|
try {
|
||||||
# Ask PSGI server for a streaming writer object by returning only the first
|
# Ask PSGI server for a streaming writer object by returning only the first
|
||||||
# two elements of the array reference
|
# two elements of the array reference
|
||||||
|
|
@ -114,13 +128,7 @@ sub call {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
# Not streaming, so immediately tell the callback to return
|
|
||||||
# the response. In the future we could use an Event framework here
|
|
||||||
# to make this a non-blocking delayed response.
|
|
||||||
$responder->($psgi_response);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub handle {
|
sub handle {
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ sub call {
|
||||||
my $res = shift;
|
my $res = shift;
|
||||||
|
|
||||||
# Close the Session if we aren't streaming
|
# Close the Session if we aren't streaming
|
||||||
if ( !$env->{'webgui.session'}->response->streaming ) {
|
if ( $env->{'webgui.session'} and $env->{'webgui.session'}->response and ! $env->{'webgui.session'}->response->streaming ) {
|
||||||
$env->{'webgui.session'}->close();
|
$env->{'webgui.session'}->close();
|
||||||
delete $env->{'webgui.session'};
|
delete $env->{'webgui.session'};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue