[Jifty-commit] r5639 - in jifty/trunk: . lib/Jifty/Plugin/REST lib/Jifty/View/Declare lib/Jifty/View/Mason lib/Jifty/View/Static share/web/templates/=
Jifty commits
jifty-commit at lists.jifty.org
Fri Aug 1 13:25:21 EDT 2008
Author: alexmv
Date: Fri Aug 1 13:25:21 2008
New Revision: 5639
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Dispatcher.pm
jifty/trunk/lib/Jifty/Handler.pm
jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm
jifty/trunk/lib/Jifty/Server.pm
jifty/trunk/lib/Jifty/Test.pm
jifty/trunk/lib/Jifty/View.pm
jifty/trunk/lib/Jifty/View/Declare/CoreTemplates.pm
jifty/trunk/lib/Jifty/View/Declare/Handler.pm
jifty/trunk/lib/Jifty/View/Mason/Handler.pm
jifty/trunk/lib/Jifty/View/Static/Handler.pm
jifty/trunk/lib/Jifty/Web.pm
jifty/trunk/share/web/templates/=/subs
Log:
r35168 at kohr-ah: chmrr | 2008-08-01 13:25:02 -0400
* Less with the LexWrap, more with the refactoring for headers
Modified: jifty/trunk/lib/Jifty/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Dispatcher.pm (original)
+++ jifty/trunk/lib/Jifty/Dispatcher.pm Fri Aug 1 13:25:21 2008
@@ -744,8 +744,9 @@
my $status = shift;
my $apache = Jifty->handler->apache;
$apache->header_out(Status => $status);
- $apache->send_http_header;
+ Jifty->handler->send_http_header;
+ # The body should just be the status
require HTTP::Status;
print STDOUT $status, ' ' , HTTP::Status::status_message($status);
}
Modified: jifty/trunk/lib/Jifty/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Handler.pm (original)
+++ jifty/trunk/lib/Jifty/Handler.pm Fri Aug 1 13:25:21 2008
@@ -254,6 +254,24 @@
$self->call_trigger('after_request', $args{cgi});
}
+=head2 send_http_header
+
+Sends any relevent HTTP headers, by calling
+L<HTML::Mason::FakeApache/send_http_header>. If this is running
+inside a standalone server, also sends the HTTP status header first.
+
+Returns false if the header has already been sent.
+
+=cut
+
+sub send_http_header {
+ my $self = shift;
+ return if $self->apache->http_header_sent;
+ $Jifty::SERVER->send_http_status if $Jifty::SERVER;
+ $self->apache->send_http_header;
+ return 1;
+}
+
=head2 cleanup_request
Dispatchers should call this at the end of each request, as a class method.
Modified: jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/REST/Dispatcher.pm Fri Aug 1 13:25:21 2008
@@ -60,7 +60,7 @@
my $apache = Jifty->handler->apache;
$apache->header_out('Content-Type' => 'text/plain; charset=UTF-8');
- $apache->send_http_header;
+ Jifty->handler->send_http_header;
print qq{
Accessing resources:
@@ -117,7 +117,7 @@
my $apache = Jifty->handler->apache;
$apache->header_out('Content-Type' => 'text/plain; charset=UTF-8');
- $apache->send_http_header;
+ Jifty->handler->send_http_header;
print __PACKAGE__->$method;
last_rule;
@@ -213,32 +213,32 @@
if ($accept =~ /ya?ml/i) {
$apache->header_out('Content-Type' => 'text/x-yaml; charset=UTF-8');
- $apache->send_http_header;
+ Jifty->handler->send_http_header;
print Jifty::YAML::Dump(@_);
}
elsif ($accept =~ /json/i) {
$apache->header_out('Content-Type' => 'application/json; charset=UTF-8');
- $apache->send_http_header;
+ Jifty->handler->send_http_header;
print Jifty::JSON::objToJson( @_ );
}
elsif ($accept =~ /j(?:ava)?s|ecmascript/i) {
$apache->header_out('Content-Type' => 'application/javascript; charset=UTF-8');
- $apache->send_http_header;
+ Jifty->handler->send_http_header;
print 'var $_ = ', Jifty::JSON::objToJson( @_, { singlequote => 1 } );
}
elsif ($accept =~ qr{^(?:application/x-)?(?:perl|pl)$}i) {
$apache->header_out('Content-Type' => 'application/x-perl; charset=UTF-8');
- $apache->send_http_header;
+ Jifty->handler->send_http_header;
print Data::Dumper::Dumper(@_);
}
elsif ($accept =~ qr|^(text/)?xml$|i) {
$apache->header_out('Content-Type' => 'text/xml; charset=UTF-8');
- $apache->send_http_header;
+ Jifty->handler->send_http_header;
print render_as_xml(@_);
}
else {
$apache->header_out('Content-Type' => 'text/html; charset=UTF-8');
- $apache->send_http_header;
+ Jifty->handler->send_http_header;
# Special case showing particular actions to show an HTML form
if ( defined $prefix
Modified: jifty/trunk/lib/Jifty/Server.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Server.pm (original)
+++ jifty/trunk/lib/Jifty/Server.pm Fri Aug 1 13:25:21 2008
@@ -35,12 +35,6 @@
=cut
-sub _send_http_status {
- print STDOUT "HTTP/1.0 ". (Jifty->handler->apache->{headers_out}->{'Status'} || '200 Jifty OK') . "\n";
-}
-use Hook::LexWrap;
-wrap 'HTML::Mason::FakeApache::send_http_header', pre => \&_send_http_status;
-
sub new {
my $class = shift;
my $self = {};
@@ -84,9 +78,17 @@
my $cgi = shift;
Jifty->handler->handle_request( cgi => $cgi );
-
}
+=head2 send_http_status
+
+Sends the HTTP status header.
+
+=cut
+
+sub send_http_status {
+ print STDOUT "HTTP/1.0 ". (Jifty->handler->apache->{headers_out}->{'Status'} || '200 Jifty OK') . "\n";
+}
=head2 print_banner
Modified: jifty/trunk/lib/Jifty/Test.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Test.pm (original)
+++ jifty/trunk/lib/Jifty/Test.pm Fri Aug 1 13:25:21 2008
@@ -431,7 +431,7 @@
}
my $server = Jifty::Server->new;
-
+ $Jifty::SERVER = $server;
return $server;
}
Modified: jifty/trunk/lib/Jifty/View.pm
==============================================================================
--- jifty/trunk/lib/Jifty/View.pm (original)
+++ jifty/trunk/lib/Jifty/View.pm Fri Aug 1 13:25:21 2008
@@ -38,7 +38,7 @@
$r->content_type || $r->content_type('text/html; charset=utf-8'); # Set up a default
unless ( $r->http_header_sent or not __PACKAGE__->auto_send_headers ) {
- $r->send_http_header();
+ Jifty->handler->send_http_header;
}
# We could perhaps install a new, faster out_method here that
Modified: jifty/trunk/lib/Jifty/View/Declare/CoreTemplates.pm
==============================================================================
--- jifty/trunk/lib/Jifty/View/Declare/CoreTemplates.pm (original)
+++ jifty/trunk/lib/Jifty/View/Declare/CoreTemplates.pm Fri Aug 1 13:25:21 2008
@@ -40,7 +40,7 @@
Jifty->handler->apache->content_type("text/html; charset=utf-8");
Jifty->handler->apache->headers_out->{'Pragma'} = 'no-cache';
Jifty->handler->apache->headers_out->{'Cache-control'} = 'no-cache';
- Jifty->handler->apache->send_http_header;
+ Jifty->handler->send_http_header;
my $writer = XML::Writer->new;
$writer->xmlDecl( "UTF-8", "yes" );
Modified: jifty/trunk/lib/Jifty/View/Declare/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/View/Declare/Handler.pm (original)
+++ jifty/trunk/lib/Jifty/View/Declare/Handler.pm Fri Aug 1 13:25:21 2008
@@ -82,7 +82,7 @@
$r->content_type || $r->content_type('text/html; charset=utf-8'); # Set up a default
unless ( Jifty->handler->apache->http_header_sent || Jifty->web->request->is_subrequest ) {
Jifty->web->session->set_cookie;
- Jifty->handler->apache->send_http_header;
+ Jifty->handler->send_http_header;
}
binmode *STDOUT;
Modified: jifty/trunk/lib/Jifty/View/Mason/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/View/Mason/Handler.pm (original)
+++ jifty/trunk/lib/Jifty/View/Mason/Handler.pm Fri Aug 1 13:25:21 2008
@@ -215,7 +215,7 @@
# Unlike under mod_perl, we cannot simply return a 301 or 302
# status and let Apache send headers, we need to explicitly
# send this header ourself.
- $r->send_http_header if $retval && grep { $retval eq $_ } ( 200, 301, 302 );
+ Jifty->handler->send_http_header if $retval && grep { $retval eq $_ } ( 200, 301, 302 );
return $retval;
}
@@ -287,7 +287,7 @@
if ($self->auto_send_headers
and not $r->http_header_sent
and (!$retval or $retval==200)) {
- $r->send_http_header();
+ Jifty->handler->send_http_header;
}
}
Modified: jifty/trunk/lib/Jifty/View/Static/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/View/Static/Handler.pm (original)
+++ jifty/trunk/lib/Jifty/View/Static/Handler.pm Fri Aug 1 13:25:21 2008
@@ -274,7 +274,7 @@
$apache->header_out( 'Content-Encoding' => "gzip" )
if ( $compression eq 'gzip' );
- $apache->send_http_header();
+ Jifty->handler->send_http_header;
}
@@ -288,7 +288,7 @@
my $self = shift;
my $apache = Jifty->handler->apache;
$apache->header_out( Status => 304 );
- $apache->send_http_header();
+ Jifty->handler->send_http_header;
return 1;
}
Modified: jifty/trunk/lib/Jifty/Web.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web.pm (original)
+++ jifty/trunk/lib/Jifty/Web.pm Fri Aug 1 13:25:21 2008
@@ -791,7 +791,7 @@
# cookie has to be sent or returning from continuations breaks
Jifty->web->session->set_cookie;
- $apache->send_http_header();
+ Jifty->handler->send_http_header;
# Mason abort, or dispatcher abort out of here
$self->mason->abort if $self->mason;
Modified: jifty/trunk/share/web/templates/=/subs
==============================================================================
--- jifty/trunk/share/web/templates/=/subs (original)
+++ jifty/trunk/share/web/templates/=/subs Fri Aug 1 13:25:21 2008
@@ -6,7 +6,7 @@
$r->content_type("text/html; charset=utf-8");
$r->headers_out->{'Pragma'} = 'no-cache';
$r->headers_out->{'Cache-control'} = 'no-cache';
-$r->send_http_header;
+Jifty->handler->send_http_header;
my $writer = XML::Writer->new;
$writer->xmlDecl( "UTF-8", "yes" );
More information about the Jifty-commit
mailing list