X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=1f87a667e4debee2b89d247ffcf0b081a248c0a8;hb=1cbdfa9b4506dadbfa520ed0a1fc33d9064be541;hp=8d665469aad0d84511c647ae8140d581a7a5e888;hpb=80ef521fc623bcd3139f0e282e23959a3dcb4e76;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 8d66546..1f87a66 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -10,18 +10,29 @@ use HTML::Entities; use HTTP::Body; use HTTP::Headers; use URI::QueryParam; +use Plack::Loader; +use Catalyst::EngineLoader; +use Encode (); +use utf8; use namespace::clean -except => 'meta'; -# input position and length -has read_length => (is => 'rw'); -has read_position => (is => 'rw'); - -has _prepared_write => (is => 'rw'); - # Amount of data to read from input on each pass our $CHUNKSIZE = 64 * 1024; +# XXX - this is only here for compat, do not use! +has env => ( is => 'rw', writer => '_set_env' ); +my $WARN_ABOUT_ENV = 0; +around env => sub { + my ($orig, $self, @args) = @_; + if(@args) { + warn "env as a writer is deprecated, you probably need to upgrade Catalyst::Engine::PSGI" + unless $WARN_ABOUT_ENV++; + return $self->_set_env(@args); + } + return $self->$orig; +}; + =head1 NAME Catalyst::Engine - The Catalyst Engine @@ -46,15 +57,23 @@ sub finalize_body { my $body = $c->response->body; no warnings 'uninitialized'; if ( blessed($body) && $body->can('read') or ref($body) eq 'GLOB' ) { - while ( !eof $body ) { - read $body, my ($buffer), $CHUNKSIZE; - last unless $self->write( $c, $buffer ); - } + my $got; + do { + $got = read $body, my ($buffer), $CHUNKSIZE; + $got = 0 unless $self->write( $c, $buffer ); + } while $got > 0; + close $body; } else { $self->write( $c, $body ); } + + my $res = $c->response; + $res->_writer->close; + $res->_clear_writer; + + return; } =head2 $self->finalize_cookies($c) @@ -83,9 +102,15 @@ sub finalize_cookies { -expires => $val->{expires}, -domain => $val->{domain}, -path => $val->{path}, - -secure => $val->{secure} || 0 + -secure => $val->{secure} || 0, + -httponly => $val->{httponly} || 0, ) ); + if (!defined $cookie) { + $c->log->warn("undef passed in '$name' cookie value - not setting cookie") + if $c->debug; + next; + } push @cookies, $cookie->as_string; } @@ -103,11 +128,37 @@ is in debug mode, or a `please come back later` message otherwise. =cut +sub _dump_error_page_element { + my ($self, $i, $element) = @_; + my ($name, $val) = @{ $element }; + + # This is fugly, but the metaclass is _HUGE_ and demands waaay too much + # scrolling. Suggestions for more pleasant ways to do this welcome. + local $val->{'__MOP__'} = "Stringified: " + . $val->{'__MOP__'} if ref $val eq 'HASH' && exists $val->{'__MOP__'}; + + my $text = encode_entities( dump( $val )); + sprintf <<"EOF", $name, $text; +
%s+
%s-