Plack

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

1.0006  Thu Oct 18 16:06:15 PDT 2012
    [INCOMPATIBLE CHANGES]
        - plackup foo.psgi will not search the file in @INC anymore before the current directory
          See https://github.com/plack/Plack/pull/343 for details (miyagawa)

    [NEW FEATURES]
        - plackup --path /foo will mount the application under /path (mattn)

    [BUG FIXES]
        - AccessLog: Fix the timezon offset for certain timezones
        - ErrorDocument: support streaming interface

1.0005  Tue Oct  9 13:33:47 PDT 2012
    [NEW FEATURES]
        - Support psgix.cleanup handlers in Apache2 (avar)
        - Added REMOTE_PORT environment variable to HTTP::Server::PSGI (dex4er)        

    [IMPROVEMENTS]
        - Documentation fix for multiple cookie values (miyagawa)
        - Delete MOD_PERL environment variable for better compatibilities (avar)
        - Split out Plack::TempBuffer as a standalone Stream::Buffered module (doy)

Changes  view on Meta::CPAN

          "?a&b=1". Now "a" becomes part of query_parameters with empty string as its value (yannk)

    [IMPROVEMENTS]
        - Support max-age options in Plack::Response cookies (remorse)
        - Pass correct protocol from HTTP::Server::PSGI to display https URL correctly (siracusa)
        - Copy Authorization header from FastCGI handler (ray1729)
        - Stop special casing COOKIE environment variable in Plack::Request headers (doy)

0.9989  Thu Jun 21 13:39:11 PDT 2012
    [IMPROVEMENTS]
        - Support streaming in Head middleware (wreis)
        - Document middleware prefixing (Jon Swartz)
        - Make Basic authentication detection case insensitive per RFC (Mark Fowler)
        - Added backlog option to FCGI handler (xaicron)

0.9988  Fri May 11 12:25:09 CEST 2012
    [BUG FIXES]
        - Fixes HTTP_HOST in HTTP::Message::PSGI #287 (doy)

0.9987  Thu May 10 07:06:32 CEST 2012
    [IMPROVEMENTS]
        - Support streaming in AccessLog::Timed (Peter Makholm)
        - Support streaming in ErrorDocument
        - Removed UTF8 hack in HTTP::Message::PSGI. Depends on URI.pm 1.59 (wreis)
        - Set Host headers correctly in HTTP::Message::PSGI #177
        - Added documentation on supported %-flags in AccessLog (ether)
        - Skip unnecessary tests on non-developer environment

0.9986  Mon Mar 12 11:26:59 PDT 2012
    [IMPROVEMENTS]
        - Use I/O handles to FCGI::Request instead of global STDIN, STDOUT etc. (chansen)
        - Improved FastCGI docs (osfameron)
        - Cascade app now returns the last response code (aristotle)

Changes  view on Meta::CPAN

        - Fixed the bug in restarter introduced in 0.9980 (nihen) #223 #234
        - Removed a debug statement left over in Plack::Util
        - Fixed warnings in Lint

0.9981  Mon Jul 18 17:24:11 PDT 2011
    [BUG FIXES]
        - Plack::Request: Added a sanity check to remove newlines from headers to follow
          the PSGI specification #224
        - HTTPParser::PP: Fixed warnings #225
        - plackup now prints errors to psgi.errors rather than STDERR
        - Fixes issues with undef returned from streaming handler in middleware #231
        - ContentLength: Do not auto-add Content-Length from block devices, pipes and
          character files

    [NEW FEATURES]
        - HTTPExceptions: Support ->as_psgi method on exceptions (doy)
        - FastCGI: Support psgix.harakiri

    [IMPROVEMENTS]
        - Lint: Added more checks to validate header values
        - StackTrace: Strip caller information since it is not useful anyway

Changes  view on Meta::CPAN

        - Added a non-blocking Hello World example in eg/dot-psgi
        - Doc cleanup

0.9978  Wed May  4 11:29:12 PDT 2011
    [TEST FIXES]
        - Fixed a failing output_encoding.t because of FCGI dependencies
        - Improved Plack::Test::Suite documentation

0.9977  Sun May  1 12:16:08 PDT 2011
    [BUG FIXES]
        - Fixed ConditionalGET to not die with streaming interface (reported by Paul Ervamaa)
        - Add a reason string to CGI/FastCGI Status header to comply with RFC 3875 (Stephen Clouse)
        - Fixed a CGI/FastCGI handler to ensure newlines are not mangled on Win32 platforms (Christian Walde)

    [IMPROVEMENTS]
        - localize @ARGV to empty when evaluating a PSGI application (https://github.com/sukria/Dancer/issues/473)
        - Fixed the use of Getopt::Long to make the pass_through flag local
        - Middleware::JSONP now supports more response types such as IO::Handle (reported by Theory)

0.9976  Fri Apr  8 18:07:11 PDT 2011
    [NEW FEATURES]

Changes  view on Meta::CPAN

        - Suppress the use of unlocalized $_ in Plack::Runner (mst)
        - Plack::Handler::Net::FastCGI is now removed from Plack core dist.
          It will be released as a separate distribution on CPAN.
        - Fixed Plack::Handler::Apache2 so that it can safely call log (Andy Wardley)
        - StackTrace: Display graceful fallback errors when $SIG{__DIE__} is overridden in the application (mkanat)

0.9968  Wed Feb  9 19:07:48 PST 2011
        - Fixed Recursive middleware to rethrow unknown exceptions. #166 (reported by waba)
        - Document response_cb. #121
        - Plack::Loader to print errors if it is really a compilation error
        - Fixed the Cascade app to work with all 404 responses with the streaming interface. #171 (reported by eevee)

0.9967  Tue Jan 25 14:26:37 PST 2011
        - Fixed StackTrace to require D::ST::WithLexicals 0.08 that supports 'message' (doy)

0.9966  Tue Jan 25 12:00:25 PST 2011
        - Fixed a memory leak in SimpleLogger (vti)
        - Support %v in AccessLog (Ranguard)
        - Force set CONTENT_LENGTH in req_to_psgi when $content is given to HTTP::Request (timbunce) #150
        - Fixed a case where SCRIPT_NAME and PATH_INFO can both get empty in req_to_psgi (doy) #163

Changes  view on Meta::CPAN

0.9945  Thu Aug 19 16:24:30 PDT 2010
        - Support executing (non-perl) CGI scripts in CGIBin and WrapCGI
        - Fixed tests for win32

0.9944  Sun Aug  8 23:35:52 PDT 2010
        - Fixed Restarter for Starlet where SIGTERM doesn't quit the process (chiba)

0.9943  Fri Jul 30 13:24:15 PDT 2010
        - Updated Apache* handler so it could duck type on Loader (jnap)
        - Added --access-log to plackup (grantm)
        - Added support for streaming stdio in Net::FastCGI handler (chansen)

0.9942  Fri Jul 23 23:42:43 PDT 2010
        - Allow passing FCGI manager object to Handler::FCGI (confound)
        - Call FCGI::Request::Finish() before pm_post_dispatch (confound)
        - Moved response_cb() to Plack::Util (confound)
        - re-enable WithLexicals now that PadWalker segfaults with 5.12 is fixed #98

0.9941  Thu Jul  8 18:17:30 PDT 2010
        - Makes Lint not warn about ASCII-only strings with UTF8 flag because they're safe

Changes  view on Meta::CPAN


0.9913  Thu Feb 25 19:14:40 PST 2010
        - Revive psgix.io in HTTP::Server::PSGI (hiratara)
        - Fix packaging issue

0.9912  Thu Feb 25 01:28:21 PST 2010
        - Fixed the possible source of memory leak in middleware + streamer + HTTP::Server::PSGI
          with perl 5.8.x (hiratara)

0.9911  Tue Feb 23 01:55:04 PST 2010
        - Removed psgix.io extension to fix streaming choke issue on HTTP::Server::PSGI (tomyhero)

0.9910  Mon Feb 22 19:03:17 PST 2010
        - This is the first non-dev release since 0.99. Read all the change logs below.
        - Support streaming in JSONP (hiratara)
        - Fixed various handler docs (markstos)
        - Added Starman and Twiggy to benchmark script
        - INCOMPATIBLE: Loader now prefers Twiggy when AnyEvent is loaded
        - Implemented (experimental) psgix.io and psgix.input.buffered extensions
        - Fixed Plack::Request POST parser to use psgix.input.buffered for better performance
        - Added PLACK_ENV environment support in plackup #63
        - Added HTTPExceptions middleware
        - Added Recursive middleware

0.99_05 Wed Feb 10 12:46:05 PST 2010
        - Changed the Loader command line options to -L from -l
        - Runner now folds --host, --port and --socket to --listen and vice verca
        - Added -D and --daemonize to plackup/Runner standard options
        - Fixed FCGI handler to work with the new --listen and --daemonize option
        - Fixed a bug in static.t where it chdir's before loading modules
        - Renamed Writer to BufferedStreaming middleware and added docs
        - Support streaming apps in Shotgun loader
        - Falls back to Standalone handler when auto-detected backend is not available (hiratara)
        - Support chunked-input in HTTP::Request->to_psgi
        - Make the Reloader work with preforked server (chiba)
        - Added 'Auto' backend in TempBuffer
        - Added Nomo backend to the benchmark script
        - Updated HTTP::Server::PSGI to support experimental psgix.input.buffered
        - Plack::Request now honors psgix.input.buffered to see psgi.input is seekable
        - Renamed Standalone handler to HTTP::Server::PSGI for consistency while keeping
          'Standalone' as a nickname

Changes  view on Meta::CPAN

        - Added a test for large POST body which revealed FCGI::Client bug
        - Added a handler for HTTP::Server::Simple::PSGI
        - Depend on a decent version of URI (tomyhero)
        - Reworked Loader API so the default loader can autodetect the backend again
        - run_app now doesn't use Try::Tiny but use plain eval {}

0.99_03 Wed Feb  3 16:09:14 PST 2010
        - Use 0 as a default address in the server_ready hook in Plack::Runner
        - Document Plack::Handler naming scheme
        - Fixed how Plack::Server::Standalone saves args
        - Supported streaming interface in Cascade and URLMap
        - mentions awesome WSGI Paste in Plack documentation
        - Removed URI caching in Plack::Request since it's fast enough
        - Fixed packaging issue due to Module::Install::Share bug (rafl)
        - Support 'file' option in App::File and its subclasses
        - Fixed SCRIPT_NAME and PATH_INFO in App::CGIBin
        - Fixed App::Directory and ::File not to use Path::Class and its canonicalization.
          It's now 300% faster!

0.99_02 Sat Jan 30 22:10:45 PST 2010
        - Fixed Plack::TempBuffer to work with 5.8 and 5.11.3

Changes  view on Meta::CPAN

        - Fixed psgi.multiprocess value on HTTP::Server::PSGI
        - PSGI/1.1 support in Lint

0.9031 Mon Jan 11 11:29:04 PST 2010
        - Fixed Plack::App::Directory directory listing by switching to Plack::MIME (tokuhirom)
          This has been broken since 0.9025
        - Fixed body filtering middleware such as Plack::Middleware::Deflater (hiratara)
          This has been broken since 0.9026

0.9030 Sat Jan  9 13:13:17 PST 2010
        - Support streaming interface in HTTP::Message::PSGI, Lint and Plack::Test (rafl)
        - plackup -e doesn't enable strict and warnings by default, like perl
        - Improved Middleware::Auth::Basic performance and error check

0.9029 Thu Jan  7 19:09:17 PST 2010
        - Fixed runtime.t to relax test condition to avoid failures on Win32 (xaicron)
        - Fixed a bug in FCGI engine where it creates a bogus response when running under a
          buffered I/O with lighttpd. (fcharlier, typester)
        - FCGI and CGI server now autoflushes STDOUT to do non-buffering output
        - Fixed a Plack::MIME bug where extensions like .mp3 fails

0.9028 Tue Jan  5 18:42:07 PST 2010
        - Fixed a long standing bug where errors are not printed correctly when the
          application dies. (tokuhirom)
        - Fixed FCGIClient passing bogus psgi.* environment values to the backend
        - Implemented psgi.streaming in all blocking servers (miyagawa, rafl)

0.9027 Sun Jan  3 16:33:23 PST 2010
        - Added new middleware Runtime that adds X-Runtime header
        - Delay load Pod::Usage in Plack::Runner and plackup

0.9026 Fri Jan  1 10:35:26 JST 2010
        - Auth::Basic now accepts an object that duck types to ->authenticate (e.g. Authen::Simple)
        - Reworked how response_cb body callback works, so Content-Length will be updated correctly

0.9025 Sat Dec 26 10:11:59 JST 2009

Changes  view on Meta::CPAN


0.9007 Sat Oct 24 17:41:33 PDT 2009
        - Fixed Server::CGI to really inline fuctions to avoid warnings
        - Fixed Middleware::AccessLog to let %{..}t strftime log format work (beppu)
        - Fixed a flush bug in gzip encoding in Middleware::Deflater
        - Fixed a bug in Middleware::AccessLog so POSIX strftime always works in English (fayland)
        - Added Middleware::ContentMD5 (Fayland)
        - Fixed plackup -r to actually reload the application code (robinsmidsrod)

0.9006 Fri Oct 23 01:21:13 PDT 2009
        - Support streaming interface in most middlewares
        - Added Middleware::Deflater (not recommended to use: see POD)
        - Document FCGI configuration in Server::FCGI pod (dhoss)
        - Inline Plack::Util functions in Server::CGI to speed up (mst)

0.9005 Wed Oct 21 20:53:19 PDT 2009
        - Switch to Filesys::Notify::Simple to watch directory to trim down deps
        - Made some dependencies optional since they're actually optional

0.9004 Tue Oct 20 22:57:48 PDT 2009
        - Fixed File::ShareDir dependency (mst)
        - App::File and Middleware::Static now auto follows symlinks (chiba)
        - Implemented plackup -r as Plack::Loader::Reloadable (nothingmuch)
        - Removed poll_cb from Writer middleware
        - Added plackup common command line options: -o for --host and -p for --port 

0.9003 Sun Oct 18 19:16:26 PDT 2009
        - Added POE to Plack::Loader autoload
        - Implemented callback style streaming in selected middlewares
        - Bump up HTTP::Parser::XS to fix memory leaks
        - Added Middleware::Chunked
        - Added Middleware::JSONP
        - Added twitter-stream.psgi example to do streaming server push
        - Fixed Middleware::StackTrace to DWIM in framework generated 500 errors
        - Fixed Restarter to do what doc says

0.9002 Wed Oct 14 11:26:28 PDT 2009
        - Added a workaround in Server::Apache2 when Location and SCRIPT_NAME don't match
        - Use Try::Tiny and parent for smaller memory footprint and better error handling

0.9001 Tue Oct 13 00:55:34 PDT 2009
        - Downgrade EUMM in inc/

MANIFEST  view on Meta::CPAN

t/Plack-Loader/shotgun.t
t/Plack-MIME/add_type.t
t/Plack-MIME/basic.t
t/Plack-MIME/fallback.t
t/Plack-Middleware/access_log.t
t/Plack-Middleware/access_log_timed.t
t/Plack-Middleware/access_log_value_zero.t
t/Plack-Middleware/auth_basic.t
t/Plack-Middleware/auth_basic_env.t
t/Plack-Middleware/auth_basic_simple.t
t/Plack-Middleware/bufferedstreaming.t
t/Plack-Middleware/cascade/basic.t
t/Plack-Middleware/cascade/streaming.t
t/Plack-Middleware/cgi-bin/cgi_dir.cgi
t/Plack-Middleware/cgi-bin/hello.cgi
t/Plack-Middleware/cgi-bin/hello.sh
t/Plack-Middleware/cgi-bin/hello2.cgi
t/Plack-Middleware/cgi-bin/hello3.cgi
t/Plack-Middleware/cgi-bin/utf8.cgi
t/Plack-Middleware/cgibin.t
t/Plack-Middleware/cgibin_exec.t
t/Plack-Middleware/chunked.t
t/Plack-Middleware/component-leak.t
t/Plack-Middleware/component.t
t/Plack-Middleware/conditional.t
t/Plack-Middleware/conditional_new.t
t/Plack-Middleware/conditionalget.t
t/Plack-Middleware/conditionalget_writer.t
t/Plack-Middleware/content_length.t
t/Plack-Middleware/directory.t
t/Plack-Middleware/error_document.t
t/Plack-Middleware/error_document_streaming_app.t
t/Plack-Middleware/errors/404.html
t/Plack-Middleware/errors/500.html
t/Plack-Middleware/file.t
t/Plack-Middleware/head.t
t/Plack-Middleware/head_streaming.t
t/Plack-Middleware/htpasswd
t/Plack-Middleware/httpexceptions.t
t/Plack-Middleware/httpexceptions_streaming.t
t/Plack-Middleware/iis6_script_name_fix.t
t/Plack-Middleware/iis7_keep_alive_fix.t
t/Plack-Middleware/jsonp.t
t/Plack-Middleware/lint.t
t/Plack-Middleware/lint_env.t
t/Plack-Middleware/lint_utf8_false_alarm.t
t/Plack-Middleware/lint_wrong_header_info.t
t/Plack-Middleware/log4perl-category.t
t/Plack-Middleware/log4perl.t
t/Plack-Middleware/log_dispatch.t
t/Plack-Middleware/order.t
t/Plack-Middleware/prefix.t
t/Plack-Middleware/psgibin.t
t/Plack-Middleware/rearrange_headers.t
t/Plack-Middleware/recursive/base.t
t/Plack-Middleware/recursive/streaming.t
t/Plack-Middleware/recursive/throw.t
t/Plack-Middleware/recursive/throw_streaming.t
t/Plack-Middleware/refresh-init.t
t/Plack-Middleware/runtime.t
t/Plack-Middleware/simple_content_filter.t
t/Plack-Middleware/simple_logger.t
t/Plack-Middleware/stacktrace/basic.t
t/Plack-Middleware/stacktrace/force.t
t/Plack-Middleware/stacktrace/multiple_exceptions.t
t/Plack-Middleware/stacktrace/sigdie.t
t/Plack-Middleware/stacktrace/streaming.t
t/Plack-Middleware/stacktrace/utf8.t
t/Plack-Middleware/static.foo
t/Plack-Middleware/static.t
t/Plack-Middleware/static.txt
t/Plack-Middleware/static_env.t
t/Plack-Middleware/urlmap.t
t/Plack-Middleware/urlmap_builder.t
t/Plack-Middleware/urlmap_env.t
t/Plack-Middleware/urlmap_ports.t
t/Plack-Middleware/wrapcgi.t

eg/dot-psgi/echo-stream.psgi  view on Meta::CPAN

use AnyEvent;
my $app = sub {
    my $env = shift;

    warn "This app needs a server that supports psgi.streaming"
        unless $env->{'psgi.streaming'};

    return sub {
        my $respond = shift;
        my $w = $respond->([ 200, ['X-Foo' => 'bar', 'Content-Type' => 'text/plain'] ]);
        my $t; $t = AE::timer 0, 1, sub {
            $t;
            # TODO handle client disconnect (broken pipe) and poll_cb
            $w->write(time . "\n");
        };
    };

eg/dot-psgi/nonblock-hello.psgi  view on Meta::CPAN

use AnyEvent;

my $app = sub {
    my $env = shift;

    warn "This app needs a server that supports psgi.streaming and psgi.nonblocking"
        unless $env->{'psgi.streaming'} && $env->{'psgi.nonblocking'};

    return sub {
        my $respond = shift;
        my $w = $respond->([ 200, ['Content-Type' => 'text/plain'] ]);
        $w->write("Hello\n");
        my $t; $t = AE::timer 2, 0, sub {
            undef $t;
            $w->write("World\n");
            $w->close;
        };

lib/HTTP/Message/PSGI.pm  view on Meta::CPAN

        REMOTE_PORT       => int( rand(64000) + 1000 ),                   # not in RFC 3875
        REQUEST_URI       => $uri->path_query || '/',                     # not in RFC 3875
        REQUEST_METHOD    => $req->method,
        'psgi.version'      => [ 1, 1 ],
        'psgi.url_scheme'   => $uri->scheme eq 'https' ? 'https' : 'http',
        'psgi.input'        => $input,
        'psgi.errors'       => *STDERR,
        'psgi.multithread'  => $FALSE,
        'psgi.multiprocess' => $FALSE,
        'psgi.run_once'     => $TRUE,
        'psgi.streaming'    => $TRUE,
        'psgi.nonblocking'  => $FALSE,
        @_,
    };

    for my $field ( $req->headers->header_field_names ) {
        my $key = uc("HTTP_$field");
        $key =~ tr/-/_/;
        $key =~ s/^HTTP_// if $field =~ /^Content-(Length|Type)$/;

        unless ( exists $env->{$key} ) {

lib/HTTP/Server/PSGI.pm  view on Meta::CPAN

                SERVER_NAME => $self->{host},
                SCRIPT_NAME => '',
                REMOTE_ADDR => $conn->peerhost,
                REMOTE_PORT => $conn->peerport || 0,
                'psgi.version' => [ 1, 1 ],
                'psgi.errors'  => *STDERR,
                'psgi.url_scheme' => $self->{ssl} ? 'https' : 'http',
                'psgi.run_once'     => Plack::Util::FALSE,
                'psgi.multithread'  => Plack::Util::FALSE,
                'psgi.multiprocess' => Plack::Util::FALSE,
                'psgi.streaming'    => Plack::Util::TRUE,
                'psgi.nonblocking'  => Plack::Util::FALSE,
                'psgix.harakiri'    => Plack::Util::TRUE,
                'psgix.input.buffered' => Plack::Util::TRUE,
                'psgix.io'          => $conn,
            };

            $self->handle_connection($env, $conn, $app);
            $conn->close;
            last if $env->{'psgix.harakiri.commit'};
        }

lib/Plack/Handler/Apache1.pm  view on Meta::CPAN


    my $env = {
        %ENV,
        'psgi.version'        => [ 1, 1 ],
        'psgi.url_scheme'     => ($ENV{HTTPS}||'off') =~ /^(?:on|1)$/i ? 'https' : 'http',
        'psgi.input'          => $r,
        'psgi.errors'         => *STDERR,
        'psgi.multithread'    => Plack::Util::FALSE,
        'psgi.multiprocess'   => Plack::Util::TRUE,
        'psgi.run_once'       => Plack::Util::FALSE,
        'psgi.streaming'      => Plack::Util::TRUE,
        'psgi.nonblocking'    => Plack::Util::FALSE,
        'psgix.harakiri'      => Plack::Util::TRUE,
    };

    if (defined(my $HTTP_AUTHORIZATION = $r->headers_in->{Authorization})) {
        $env->{HTTP_AUTHORIZATION} = $HTTP_AUTHORIZATION;
    }

    my $vpath    = $env->{SCRIPT_NAME} . ($env->{PATH_INFO} || '');

lib/Plack/Handler/Apache2.pm  view on Meta::CPAN


    my $env = {
        %ENV,
        'psgi.version'           => [ 1, 1 ],
        'psgi.url_scheme'        => ($ENV{HTTPS}||'off') =~ /^(?:on|1)$/i ? 'https' : 'http',
        'psgi.input'             => $r,
        'psgi.errors'            => *STDERR,
        'psgi.multithread'       => Plack::Util::FALSE,
        'psgi.multiprocess'      => Plack::Util::TRUE,
        'psgi.run_once'          => Plack::Util::FALSE,
        'psgi.streaming'         => Plack::Util::TRUE,
        'psgi.nonblocking'       => Plack::Util::FALSE,
        'psgix.harakiri'         => Plack::Util::TRUE,
        'psgix.cleanup'          => Plack::Util::TRUE,
        'psgix.cleanup.handlers' => [],
    };

    if (defined(my $HTTP_AUTHORIZATION = $r->headers_in->{Authorization})) {
        $env->{HTTP_AUTHORIZATION} = $HTTP_AUTHORIZATION;
    }

lib/Plack/Handler/CGI.pm  view on Meta::CPAN


    my $env = {
        %ENV,
        'psgi.version'    => [ 1, 1 ],
        'psgi.url_scheme' => ($ENV{HTTPS}||'off') =~ /^(?:on|1)$/i ? 'https' : 'http',
        'psgi.input'      => *STDIN,
        'psgi.errors'     => *STDERR,
        'psgi.multithread'  => 0,
        'psgi.multiprocess' => 1,
        'psgi.run_once'     => 1,
        'psgi.streaming'    => 1,
        'psgi.nonblocking'  => 1,
        %{ $override_env },
    };

    delete $env->{HTTP_CONTENT_TYPE};
    delete $env->{HTTP_CONTENT_LENGTH};
    $env->{'HTTP_COOKIE'} ||= $ENV{COOKIE}; # O'Reilly server bug

    if (!exists $env->{PATH_INFO}) {
        $env->{PATH_INFO} = '';

lib/Plack/Handler/FCGI.pm  view on Meta::CPAN

        my $env = {
            %env,
            'psgi.version'      => [1,1],
            'psgi.url_scheme'   => ($env{HTTPS}||'off') =~ /^(?:on|1)$/i ? 'https' : 'http',
            'psgi.input'        => $self->{stdin},
            'psgi.errors'       => 
                ($self->{keep_stderr} ? \*STDERR : $self->{stderr}),
            'psgi.multithread'  => Plack::Util::FALSE,
            'psgi.multiprocess' => defined $proc_manager,
            'psgi.run_once'     => Plack::Util::FALSE,
            'psgi.streaming'    => Plack::Util::TRUE,
            'psgi.nonblocking'  => Plack::Util::FALSE,
            'psgix.harakiri'    => defined $proc_manager,
            'psgix.cleanup'     => 1,
            'psgix.cleanup.handlers' => [],
        };

        delete $env->{HTTP_CONTENT_TYPE};
        delete $env->{HTTP_CONTENT_LENGTH};

        # lighttpd munges multiple slashes in PATH_INFO into one. Try recovering it

lib/Plack/Loader/Shotgun.pm  view on Meta::CPAN

            close $read;
            waitpid($pid, 0);

            return $res;
        } else {
            # child
            close $read;

            my $res;
            try {
                $env->{'psgi.streaming'} = 0;
                $res = $self->{builder}->()->($env);
                my @body;
                Plack::Util::foreach($res->[2], sub { push @body, $_[0] });
                $res->[2] = \@body;
            } catch {
                $env->{'psgi.errors'}->print($_);
                $res = [ 500, [ "Content-Type", "text/plain" ], [ "Internal Server Error" ] ];
            };

            print {$write} Storable::freeze($res);

lib/Plack/Middleware.pm  view on Meta::CPAN

  sub call {
      my($self, $env) = @_;
      # pre-processing $env
      my $res = $self->app->($env);
      # post-processing $res
      return $res;
  }

The tricky thing about post-processing the response is that it could
either be an immediate 3 element array ref, or a code reference that
implements the delayed (streaming) interface.

Dealing with these two types of response in each piece of middleware
is pointless, so you're recommended to use the C<response_cb> wrapper
function in L<Plack::Util> when implementing a post processing
middleware.

  sub call {
      my($self, $env) = @_;
      # pre-processing $env
      my $res = $self->app->($env);

lib/Plack/Middleware.pm  view on Meta::CPAN

do:

  Plack::Util::response_cb($res, sub {
      my $res = shift;
      @$res = ($new_status, $new_headers, $new_body); # THIS WORKS
      return;
  });

The third element of the response array ref is a body, and it could
be either an arrayref or L<IO::Handle>-ish object. The application could
also make use of the C<$writer> object if C<psgi.streaming> is in
effect, and in this case, the third element will not exist
(C<@$res == 2>). Dealing with these variants is again really painful,
and C<response_cb> can take care of that too, by allowing you to return
a content filter as a code reference.

  # replace all "Foo" in content body with "Bar"
  Plack::Util::response_cb($res, sub {
      my $res = shift;
      return sub {
          my $chunk = shift;

lib/Plack/Middleware/BufferedStreaming.pm  view on Meta::CPAN

no warnings;
use Carp;
use Plack::Util;
use Plack::Util::Accessor qw(force);
use Scalar::Util qw(weaken);
use parent qw(Plack::Middleware);

sub call {
    my ( $self, $env ) = @_;

    my $caller_supports_streaming = $env->{'psgi.streaming'};
    $env->{'psgi.streaming'} = Plack::Util::TRUE;

    my $res = $self->app->($env);
    return $res if $caller_supports_streaming && !$self->force;

    if ( ref($res) eq 'CODE' ) {
        my $ret;

        $res->(sub {
            my $write = shift;

            if ( @$write == 2 ) {
                my @body;

lib/Plack/Middleware/BufferedStreaming.pm  view on Meta::CPAN

        return $res;
    }
}

1;

__END__

=head1 NAME

Plack::Middleware::BufferedStreaming - Enable buffering for non-streaming aware servers

=head1 SYNOPSIS

  enable "BufferedStreaming";

=head1 DESCRIPTION

Plack::Middleware::BufferedStreaming is a PSGI middleware component
that wraps the application that uses C<psgi.streaming> interface to
run on the servers that do not support the interface, by buffering the
writer output to a temporary buffer.

This middleware doesn't do anything and bypass the application if the
server supports C<psgi.streaming> interface, unless you set C<force>
option (see below).

=head1 OPTIONS

=over 4

=item force

Force enable this middleware only if the container supports C<psgi.streaming>.

=back

=head1 AUTHOR

Yuval Kogman

Tatsuhiko Miyagawa

=cut

lib/Plack/Middleware/JSONP.pm  view on Meta::CPAN


    enable "JSONP", callback_key => 'jsonp';

=head1 DESCRIPTION

Plack::Middleware::JSONP wraps JSON response, which has Content-Type
value either C<text/javascript> or C<application/json> as a JSONP
response which is specified with the C<callback> query parameter. The
name of the parameter can be set while enabling the middleware.

This middleware only works with a non-streaming response, and doesn't
touch the response otherwise.

=head1 AUTHOR

Tatsuhiko Miyagawa

=head1 SEE ALSO

L<Plack>

lib/Plack/Middleware/Lint.pm  view on Meta::CPAN

    unless (ref($env->{'psgi.version'}) eq 'ARRAY') {
        die("psgi.version should be ArrayRef: $env->{'psgi.version'}");
    }
    unless (scalar(@{$env->{'psgi.version'}}) == 2) {
        die('psgi.version should contain 2 elements, not ', scalar(@{$env->{'psgi.version'}}));
    }
    unless ($env->{'psgi.url_scheme'} =~ /^https?$/) {
        die("psgi.url_scheme should be 'http' or 'https': ", $env->{'psgi.url_scheme'});
    }
    if ($env->{"psgi.version"}->[1] == 1) { # 1.1
        for my $param (qw(streaming nonblocking run_once)) {
            unless (exists $env->{"psgi.$param"}) {
                die("Missing psgi.$param");
            }
        }
    }
    if ($env->{HTTP_CONTENT_TYPE}) {
        die('HTTP_CONTENT_TYPE should not exist');
    }
    if ($env->{HTTP_CONTENT_LENGTH}) {
        die('HTTP_CONTENT_LENGTH should not exist');

lib/Plack/Middleware/Lint.pm  view on Meta::CPAN


sub is_possibly_fh {
    my $fh = shift;

    ref $fh eq 'GLOB' &&
    *{$fh}{IO} &&
    *{$fh}{IO}->can('getline');
}

sub validate_res {
    my ($self, $res, $streaming) = @_;

    unless (ref($res) eq 'ARRAY' or ref($res) eq 'CODE') {
        die("Response should be array ref or code ref: $res");
    }

    if (ref $res eq 'CODE') {
        return $self->response_cb($res, sub { $self->validate_res(@_, 1) });
    }

    unless (@$res == 3 || ($streaming && @$res == 2)) {
        die('Response needs to be 3 element array, or 2 element in streaming');
    }

    unless ($res->[0] =~ /^\d+$/ && $res->[0] >= 100) {
        die("Status code needs to be an integer greater than or equal to 100: $res->[0]");
    }

    unless (ref $res->[1] eq 'ARRAY') {
        die("Headers needs to be an array ref: $res->[1]");
    }

lib/Plack/Middleware/Lint.pm  view on Meta::CPAN

            die("Response headers MUST consist only of letters, digits, _ or - and MUST start with a letter. Header: $key");
        }
        if ($val =~ /[\000-\037]/) {
            die("Response headers MUST NOT contain characters below octal \037. Header: $key. Value: $val");
        }
        unless (defined $val) {
            die("Response headers MUST be a defined string. Header: $key");
        }
    }

    # @$res == 2 is only right in psgi.streaming, and it's already checked.
    unless (@$res == 2 ||
            ref $res->[2] eq 'ARRAY' ||
            Plack::Util::is_real_fh($res->[2]) ||
            is_possibly_fh($res->[2]) ||
            (blessed($res->[2]) && $res->[2]->can('getline'))) {
        die("Body should be an array ref or filehandle: $res->[2]");
    }

    if (ref $res->[2] eq 'ARRAY' && grep _has_wide_char($_), @{$res->[2]}) {
        die("Body must be bytes and should not contain wide characters (UTF-8 strings)");

lib/Plack/Middleware/StackTrace.pm  view on Meta::CPAN


This middleware is enabled by default when you run L<plackup> in the
default I<development> mode.

You're recommended to use this middleware during the development and
use L<Plack::Middleware::HTTPExceptions> in the deployment mode as a
replacement, so that all the exceptions thrown from your application
still get caught and rendered as a 500 error response, rather than
crashing the web server.

Catching errors in streaming response is not supported.

=head2 Stack Trace Module

The L<Devel::StackTrace::WithLexicals> module will be used to capture the stack trace
if the installed version is 0.08 or later. Otherwise L<Devel::StackTrace> is used.

=head2 Performance

Gathering the information for a stack trace via L<Devel::StackTrace> is slow,
and L<Devel::StackTrace::WithLexicals> is significantly slower still.

lib/Plack/Test/Suite.pm  view on Meta::CPAN

            my $res = $cb->(GET "http://127.0.0.1/?name=miyagawa");
            return if $res->code == 501;

            is $res->code, 200;
            is $res->message, 'OK';
            is $res->header('content_type'), 'text/plain';
            is $res->content, 'Hello, name=miyagawa';
        },
        sub {
            my $env = shift;
            $env->{'psgi.streaming'} or return [ 501, ['Content-Type','text/plain'], [] ];
            return sub {
                my $respond = shift;
                $respond->([
                    200,
                    [ 'Content-Type' => 'text/plain', ],
                    [ 'Hello, ' . $env->{QUERY_STRING} ],
                ]);
            }
        },
    ],
    [
        'coderef streaming',
        sub {
            my $cb = shift;
            my $res = $cb->(GET "http://127.0.0.1/?name=miyagawa");
            return if $res->code == 501;

            is $res->code, 200;
            is $res->message, 'OK';
            is $res->header('content_type'), 'text/plain';
            is $res->content, 'Hello, name=miyagawa';
        },
        sub {
            my $env = shift;
            $env->{'psgi.streaming'} or return [ 501, ['Content-Type','text/plain'], [] ];

            return sub {
                my $respond = shift;

                my $writer = $respond->([
                    200,
                    [ 'Content-Type' => 'text/plain', ],
                ]);

                $writer->write("Hello, ");

t/Plack-Handler/fcgi_cleanup.t  view on Meta::CPAN

                sub { $r{before}{handled} = time };

            # The app
            my $res = sub {
                my ($env) = @_;

                $r{enabled} = $env->{'psgix.cleanup'};
                push @{ $env->{'psgix.cleanup.handlers'} },
                    sub { sleep 3; $r{handled} = time };

                # Use streaming response to verify that cleanup happens
                # even after that.
                sub { shift->( [ 200, [], [ $r{handled} . ':' . time ] ] ) }
            }->($env);

            Plack::Util::response_cb( $res, sub {
                $r{response_cb} = {
                    enabled => $env->{'psgix.cleanup'},
                    ran     => $r{handled},
                    handler_count =>
                        scalar @{ $env->{'psgix.cleanup.handlers'} },

t/Plack-Middleware/access_log_timed.t  view on Meta::CPAN

}

{
    $log = "";
    $test_req->(GET "http://localhost/foo%20bar?baz=baz");
    like $log, qr@GET /foo%20bar\?baz=baz HTTP/1\.1@;
}



# Testing streaming responses

$log = "";
$handler = builder {
    enable "Plack::Middleware::AccessLog::Timed",
        logger => sub { $log .= "@_" };
    
    sub { 
        return sub { 
            my $writer = $_[0]->( [ 200, [ 'Content-Type' => 'text/plain' ] ] );
            $writer->write("OK");

t/Plack-Middleware/conditionalget_writer.t  view on Meta::CPAN

            $writer->write($_) for ( qw( kling klang klong ) );
            $writer->close;
        };

    };
};

test_psgi $handler, sub {
    my $cb = shift;

    my $res = $cb->( GET "http://localhost/streaming-klingklangklong" );
    is $res->code, 200, 'Response HTTP status';
    is $res->content, 'klingklangklong', 'Response content';

    $res = $cb->( GET
        "http://localhost/streaming-klingklangklong",
        'If-None-Match' => 'DEADBEEF'
    );
    is $res->code, 304, 'Response HTTP status';
    ok(!$res->content);
};

done_testing;



( run in 0.688 second using v1.01-cache-2.11-cpan-4d50c553e7e )