Caching is breaking something

This commit is contained in:
Patrick Donelan 2009-10-10 12:11:22 +11:00
parent e04b1ebc9d
commit 5982b2728c
3 changed files with 51 additions and 28 deletions

View file

@ -1,8 +1,9 @@
BEGIN {
# This is just a temporary hack
our $WEBGUI_ROOT = '/data/WebGUI';
our $WEBGUI_ROOT = '/data/WebGUI';
our $WEBGUI_DOMAINS = '/data/domains';
our $WEBGUI_CONFIG = 'dev.localhost.localdomain';
our $WEBGUI_CONFIG = 'dev.localhost.localdomain';
}
use local::lib $WEBGUI_ROOT;
use WebGUI;
@ -11,26 +12,30 @@ use Plack::Builder;
my $app = sub {
my $env = shift;
$env->{'wg.WEBGUI_ROOT'} = $WEBGUI_ROOT;
$env->{'wg.WEBGUI_CONFIG'} = "$WEBGUI_CONFIG.conf";
$env->{'wg.DIR_CONFIG.WebguiRoot'} = $env->{'wg.WEBGUI_ROOT'};
$env->{'wg.WEBGUI_ROOT'} = $WEBGUI_ROOT;
$env->{'wg.WEBGUI_CONFIG'} = "$WEBGUI_CONFIG.conf";
$env->{'wg.DIR_CONFIG.WebguiRoot'} = $env->{'wg.WEBGUI_ROOT'};
$env->{'wg.DIR_CONFIG.WebguiConfig'} = $env->{'wg.WEBGUI_CONFIG'};
WebGUI::handle_psgi($env);
};
# Apply some Middleware
builder {
# /extras
enable Plack::Middleware::Static
path => qr{^/extras/}, root => "$WEBGUI_ROOT/www/";
enable Plack::Middleware::Static
path => qr{^/extras/},
root => "$WEBGUI_ROOT/www/";
# /uploads (ignore .wgaccess for now..)
enable Plack::Middleware::Static
path => qr{^/uploads/}, root => "$WEBGUI_DOMAINS/dev.localhost.localdomain/public/";
enable Plack::Middleware::Static
path => qr{^/uploads/},
root => "$WEBGUI_DOMAINS/dev.localhost.localdomain/public/";
enable Plack::Middleware::XFramework framework => 'WebGUI';
enable Plack::Middleware::AccessLog format => "combined";
# Already enabled by plackup script
# enable Plack::Middleware::AccessLog format => "combined";
$app;
}
}

View file

@ -78,8 +78,13 @@ A reference to a WebGUI::Config object. One will be created if it isn't specifie
sub authen {
my ($request, $username, $password, $config) = @_;
$request = Apache2::Request->new($request);
my $server = Apache2::ServerUtil->server;
my $server;
if ($request->isa('WebGUI::Session::Plack')) {
$server = $request->server;
} else {
$request = Apache2::Request->new($request);
$server = Apache2::ServerUtil->server; #instantiate the server api
}
my $status = Apache2::Const::OK;
# set username and password if it's an auth handler
@ -173,15 +178,15 @@ sub handler {
my $gotMatch = 0;
# handle basic auth
# my $auth = $request->headers_in->{'Authorization'};
# if ($auth =~ m/^Basic/) { # machine oriented
# # Get username and password from Apache and hand over to authen
# $auth =~ s/Basic //;
# authen($request, split(":", MIME::Base64::decode_base64($auth), 2), $config);
# }
# else { # realm oriented
# $request->push_handlers(PerlAuthenHandler => sub { return WebGUI::authen($request, undef, undef, $config)});
# }
my $auth = $request->headers_in->{'Authorization'};
if ($auth =~ m/^Basic/) { # machine oriented
# Get username and password from Apache and hand over to authen
$auth =~ s/Basic //;
authen($request, split(":", MIME::Base64::decode_base64($auth), 2), $config);
}
else { # realm oriented
$request->push_handlers(PerlAuthenHandler => sub { return WebGUI::authen($request, undef, undef, $config)});
}
# url handlers
@ -212,6 +217,8 @@ sub handler {
return Apache2::Const::DECLINED;
}
sub handle_psgi {
my $env = shift;
require WebGUI::Session::Plack;

View file

@ -19,7 +19,7 @@ sub new {
require Plack::Response;
my $request = Plack::Request->new( $p{env} );
my $response = $request->new_response;
my $response = $request->new_response(200);
my $self = bless {
%p,
@ -59,10 +59,17 @@ sub protocol { shift->request->protocol(@_) }
sub status { shift->response->status(@_) }
sub status_line {}
sub auth_type {
# should we support this?
}
# TODO: I suppose this should do some sort of IO::Handle thing
my @body;
sub print { shift; push @body, @_ }
my $sendfile;
sub sendfile { shift; $sendfile = shift; }
sub dir_config {
my $self = shift;
my $c = shift;
@ -100,7 +107,11 @@ sub push_handlers {
sub finalize {
my $self = shift;
$self->response->body(\@body);
if ($sendfile && open my $fh, '<', $sendfile) {
$self->response->body( $fh );
} else {
$self->response->body( $sendfile || \@body);
}
return $self->response->finalize;
}