Browse files

Merge branch 'master' of github.com:miyagawa/Plack

  • Loading branch information...
2 parents d8577fb + 84b4178 commit 7029cff68e41d77e1e7110704db7230acd11e93d @miyagawa miyagawa committed Apr 14, 2012
Showing with 36 additions and 14 deletions.
  1. +28 −6 lib/Plack/Middleware/AccessLog.pm
  2. +7 −7 lib/Plack/Middleware/Conditional.pm
  3. +1 −1 t/Plack-Handler/fcgi.t
View
34 lib/Plack/Middleware/AccessLog.pm
@@ -8,8 +8,8 @@ use Carp ();
use Plack::Util;
my %formats = (
- common => "%h %l %u %t \"%r\" %>s %b",
- combined => "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"",
+ common => '%h %l %u %t "%r" %>s %b',
+ combined => '%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"',
);
use POSIX ();
@@ -64,7 +64,7 @@ sub log_line {
h => sub { $env->{REMOTE_ADDR} || '-' },
l => sub { '-' },
u => sub { $env->{REMOTE_USER} || '-' },
- t => sub { "[" . $strftime->("%d/%b/%Y:%H:%M:%S %z", localtime) . "]" },
+ t => sub { "[" . $strftime->('%d/%b/%Y:%H:%M:%S %z', localtime) . "]" },
r => sub { _safe($env->{REQUEST_METHOD}) . " " . _safe($env->{REQUEST_URI}) .
" " . $env->{SERVER_PROTOCOL} },
s => sub { $status },
@@ -151,11 +151,33 @@ default C<development> environment.
=item format
enable "Plack::Middleware::AccessLog",
- format => "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"";
+ format => '%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"';
Takes a format string (or a preset template C<combined> or C<custom>)
-to specify the log format. This middleware implements subset of
-Apache's LogFormat templates.
+to specify the log format. This middleware implements a subset of
+L<Apache's LogFormat templates|http://httpd.apache.org/docs/2.0/mod/mod_log_config.html>:
+
+ %% a percent sign
+ %h REMOTE_ADDR from the PSGI environment, or -
+ %l remote logname not implemented (currently always -)
+ %u REMOTE_USER from the PSGI environment, or -
+ %t [local timestamp, in default format]
+ %r REQUEST_METHOD, REQUEST_URI and SERVER_PROTOCOL from the PSGI environment
+ %s the HTTP status code of the response
+ %b content length
+ %T custom field for handling times in subclasses
+ %D custom field for handling sub-second times in subclasses
+ %v SERVER_NAME from the PSGI environment, or -
+ %V HTTP_HOST or SERVER_NAME from the PSGI environment, or -
+
+Some of these format fields are only supported by middleware that subclasses C<AccessLog>.
+
+In addition, custom values can be referenced, using C<%{name}>,
+with one of the mandatory modifier flags C<i>, C<o> or C<t>:
+
+ %{variable-name}i HTTP_VARIABLE_NAME value from the PSGI environment
+ %{header-name}o header-name header
+ %{time-format]t localtime in the specified strftime format
=item logger
View
14 lib/Plack/Middleware/Conditional.pm
@@ -32,21 +32,21 @@ Plack::Middleware::Conditional - Conditional wrapper for Plack middleware
use Plack::Builder;
builder {
- enable_if { $_[0]->{REMOTE_ADDR} eq '127.0.0.1' } 'StackTrace';
+ enable_if { $_[0]->{REMOTE_ADDR} eq '127.0.0.1' } 'StackTrace', force => 1;
$app;
};
- # Or more raw version of it
+ # or using the OO interface:
$app = Plack::Middleware::Conditional->wrap(
$app,
- condition => sub { my $env = shift; $env->{HTTP_USER_AGENT} =~ /WebKit/ },
- builder => sub { Plack::Middleware::SuperAdminConsole->wrap($_[0], @args) },
+ condition => sub { $_[0]->{REMOTE_ADDR} eq '127.0.0.1' },
+ builder => sub { Plack::Middleware::StackTrace->wrap($_[0], force => 1) },
);
=head1 DESCRIPTION
Plack::Middleware::Conditional is a piece of meta-middleware, to run a
-specific middleware component under the runtime condition. The goal of
+specific middleware component under runtime conditions. The goal of
this middleware is to avoid baking runtime configuration options in
individual middleware components, and rather share them as another
middleware component.
@@ -72,8 +72,8 @@ the explanation and might not exist.
};
Note that in the last example I<MobileDetector> should come first
-because the conditional check runs in I<pre-run> condition, which is
-from outer to inner and that is from the top to the bottom in the
+because the conditional check runs in I<pre-run> conditions, which is
+from outer to inner: that is, from the top to the bottom in the
Builder DSL code.
=head1 AUTHOR
View
2 t/Plack-Handler/fcgi.t
@@ -2,7 +2,7 @@ use strict;
use warnings;
use Test::More;
-plan skip_all => "Requires lighttpd: author only" unless -e ".git";
+plan skip_all => "Requires lighttpd: author only" unless -e '.git';
use Test::Requires qw(FCGI FCGI::ProcManager);
use Plack;

0 comments on commit 7029cff

Please sign in to comment.