Plasp
view release on metacpan or search on metacpan
lib/Plasp/App.pm view on Meta::CPAN
# Define a callback once server is ready to write data to client. The
# callback is called and passed subroutine called a responder.
my $callback = sub {
# Setup a hash here holding references to various objects at this
# scope, so that the closures for calling the responder will be
# able to write to this scope.
my %refs = ( responder => shift );
# If a responder is passed in, that means streaming response is
# supported so pass a closure to write out headers and body
if ( $refs{responder} ) {
$_asp->Response->_headers_writer(
sub { $refs{writer} = $refs{responder}->( \@_ ) }
);
$_asp->Response->_content_writer(
sub { $refs{writer}->write( @_ ) }
);
}
lib/Plasp/App.pm view on Meta::CPAN
$resp->Flush;
if ( $refs{writer} ) {
# Close the writer so as to conclude the response to the
# client
$refs{writer}->close;
} else {
# If not using streaming response, then save response
# for reference later
$refs{status} = $resp->Status;
$refs{headers} = $resp->Headers;
$refs{body} = [ $resp->Output ];
}
# Ensure destruction!
$_asp->cleanup;
}
};
# If a responder was passed in, then no need to return anything,
# but otherwise need to return the PSGI three-element array
unless ( $refs{responder} ) {
return $success
? \( @refs{qw(status headers body)} )
: $error_response;
}
};
if ( $_asp->req->env->{'psgi.streaming'} ) {
# Return the callback subroutine if streaming is supported
return $callback;
} else {
# Manually call the callback to get response
return $callback->();
}
}
}
lib/Plasp/Response.pm view on Meta::CPAN
clearer => 'clear_Output',
handles_via => 'String',
handles => {
OutputLength => 'length',
OutputSubstr => 'substr',
Write => 'append',
},
);
# This attribute has no effect output will always be buffered, even in cases
# of streaming response.
has 'Buffer' => (
is => 'ro',
default => 1,
);
=item $Response->{CacheControl}
Default C<"private">, when set to public allows proxy servers to cache the
content. This setting controls the value set in the HTTP header C<Cache-Control>
lib/Plasp/Response.pm view on Meta::CPAN
# Set the Expires header from either Expires or ExpiresAbsolute
# attribute
if ( $self->Expires ) {
push @{ $self->Headers },
Expires => time2str( time + $self->Expires );
} elsif ( $self->ExpiresAbsolute ) {
push @{ $self->Headers }, Expires => $self->ExpiresAbsolute;
}
# In the case that streaming response is supported, a _headers_writer
# should be defined. If so, use it to write out the Status and Headers
if ( $self->_headers_writer ) {
$self->_headers_writer->( $self->Status, $self->Headers );
}
# Headers are written, so don't write them out again, even if not
# streaming response
$self->_set_headers_written;
}
my $body = $self->Output;
# Process HTML::FillInForm
if ( $self->FormFill ) {
my @errors;
$body =~ s/(\<form[^\>]*\>.*?\<\/form\>)/
{
lib/Plasp/Response.pm view on Meta::CPAN
}
if ( my $charset = $self->Charset ) {
$body = Encode::encode( $charset, $body );
} elsif ( $self->ContentType =~ /text|javascript|json/ ) {
$body = Encode::encode( 'UTF-8', $body );
}
if ( $self->_content_writer ) {
# In the case that streaming response is supported, a _content_writer
# should be defined. If so, use it to write out the body, then clear
# Output buffer.
$self->_content_writer->( $body );
$self->Clear;
} else {
# If streaming response not supported, then keep track of a flushed
# offset and save the output up to that point.
$self->_flushed_offset( $self->OutputLength );
}
}
=item $Response->Include($filename, @args)
This API extension calls the routine compiled from asp script in C<$filename>
t/lib/Mock/Plasp.pm view on Meta::CPAN
HTTP_DATE => 'Mon, 14 Sep 2020 00:00:00 GMT',
HTTP_REFERER => 'https://127.0.0.1/index.asp',
HTTP_USER_AGENT => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:80.0) Gecko/20100101 Firefox/80.0',
'psgi.version' => [ 1, 1 ],
'psgi.url_scheme' => $uri->scheme,
'psgi.input' => $body_fh,
'psgi.errors' => \*STDERR,
'psgi.multithreaded' => Plack::Util::TRUE,
'psgi.run_once' => Plack::Util::FALSE,
'psgi.non_blocking' => Plack::Util::FALSE,
'psgi.streaming' => Plack::Util::TRUE,
'psgix.logger' => sub { my ( $l, $m ) = @{ $_[0] }{qw(level message)}; mock_logger->$l( $m ) },
'psgix.session' => { SessionID => '1234567890abcdef0987654321fedcba' },
'psgix.session.options' => { id => '1234567890abcdef0987654321fedcba' },
'psgix.harakiri' => Plack::Util::TRUE,
'psgix.harakiri.commit' => Plack::Util::FALSE,
'psgix.cleanup' => Plack::Util::FALSE,
);
my $content = '';
if ( $type eq 'get' ) {
( run in 0.259 second using v1.01-cache-2.11-cpan-4d50c553e7e )