Permalink
Browse files

paragraphized

  • Loading branch information...
1 parent e6445a2 commit ff0e6defea24399c2dfcd9047ceabf870de4534b @miyagawa miyagawa committed Sep 7, 2009
Showing with 210 additions and 58 deletions.
  1. +92 −26 PSGI.pod
  2. +118 −32 PSGI/FAQ.pod
View
118 PSGI.pod
@@ -4,13 +4,18 @@ PSGI - Perl Web Server Gateway Interface Specification
=head1 ABSTRACT
-This document specifies a standard interface between web servers and Perl web applications or frameworks, to promote web application portability and reduce the duplicated efforts by web application framework developers.
+This document specifies a standard interface between web servers and
+Perl web applications or frameworks, to promote web application
+portability and reduce the duplicated efforts by web application
+framework developers.
=head1 SPECIFICATION
=head2 Applications
-A PSGI application is a Perl code reference. It takes exactly one argument, the environment and returns an array reference of exactly three values.
+A PSGI application is a Perl code reference. It takes exactly one
+argument, the environment and returns an array reference of exactly
+three values.
sub app {
my $env = shift;
@@ -23,41 +28,67 @@ A PSGI application is a Perl code reference. It takes exactly one argument, the
=head3 The Environment
-The environment MUST be a hash reference that includes CGI-like headers. The application is free to modify the environment. The environment is required to include these variables (adopted from PEP333, Rack and JSGI) except when they'd be empty, but see below:
+The environment MUST be a hash reference that includes CGI-like
+headers. The application is free to modify the environment. The
+environment is required to include these variables (adopted from
+PEP333, Rack and JSGI) except when they'd be empty, but see below:
=over 4
=item *
-C<REQUEST_METHOD>: The HTTP request method, such as "GET" or "POST". This cannot ever be an empty string, and so is always required.
+C<REQUEST_METHOD>: The HTTP request method, such as "GET" or
+"POST". This cannot ever be an empty string, and so is always
+required.
=item *
-C<SCRIPT_NAME>: The initial portion of the request URL's I<path> that corresponds to the application, so that the application knows its virtual "location". This may be an empty string, if the application corresponds to the "root" of the server.
+C<SCRIPT_NAME>: The initial portion of the request URL's I<path> that
+corresponds to the application, so that the application knows its
+virtual "location". This may be an empty string, if the application
+corresponds to the "root" of the server.
=item *
-C<PATH_INFO>: The remainder of the request URL's "path", designating the virtual "location" of the request's target within the application. This may be an empty string, if the request URL targets the application root and does not have a trailing slash. This value may be percent-encoded when I originating from a URL.
+C<PATH_INFO>: The remainder of the request URL's "path", designating
+the virtual "location" of the request's target within the
+application. This may be an empty string, if the request URL targets
+the application root and does not have a trailing slash. This value
+may be percent-encoded when I originating from a URL.
=item *
-C<QUERY_STRING>: The portion of the request URL that follows the C<?>, if any. May be empty, but is always required.
+C<QUERY_STRING>: The portion of the request URL that follows the C<?>,
+if any. May be empty, but is always required.
=item *
-C<SERVER_NAME>, C<SERVER_PORT>: When combined with C<SCRIPT_NAME> and C<PATH_INFO>, these variables can be used to complete the URL. Note, however, that C<HTTP_HOST>, if present, should be used in preference to C<SERVER_NAME> for reconstructing the request URL. C<SERVER_NAME> and C<SERVER_PORT> can never be empty strings, and so are always required.
+C<SERVER_NAME>, C<SERVER_PORT>: When combined with C<SCRIPT_NAME> and
+C<PATH_INFO>, these variables can be used to complete the URL. Note,
+however, that C<HTTP_HOST>, if present, should be used in preference
+to C<SERVER_NAME> for reconstructing the request URL. C<SERVER_NAME>
+and C<SERVER_PORT> can never be empty strings, and so are always
+required.
=item *
-C<SERVER_PROTOCOL>: The version of the protocol the client used to send the request. Typically this will be something like "HTTP/1.0" or "HTTP/1.1" and may be used by the application to determine how to treat any HTTP request headers.
+C<SERVER_PROTOCOL>: The version of the protocol the client used to
+send the request. Typically this will be something like "HTTP/1.0" or
+"HTTP/1.1" and may be used by the application to determine how to
+treat any HTTP request headers.
=item *
-C<HTTP_> Variables: Variables corresponding to the client-supplied HTTP request headers (i.e., variables whose names begin with C<HTTP_>). The presence or absence of these variables should correspond with the presence or absence of the appropriate HTTP header in the request.
+C<HTTP_> Variables: Variables corresponding to the client-supplied
+HTTP request headers (i.e., variables whose names begin with
+C<HTTP_>). The presence or absence of these variables should
+correspond with the presence or absence of the appropriate HTTP header
+in the request.
=back
-In addition to this, the PSGI environment MUST include these PSGI-specific variables:
+In addition to this, the PSGI environment MUST include these
+PSGI-specific variables:
=over 4
@@ -85,15 +116,27 @@ The PSGI environment MAY include these optional PSGI variables:
=item *
-C<psgi.run_once>: true if the server expects (but does not guarantee!) that the application will only be invoked this one time during the life of its containing process. Normally, this will only be true for a server based on CGI (or something similar).
+C<psgi.run_once>: true if the server expects (but does not guarantee!)
+that the application will only be invoked this one time during the
+life of its containing process. Normally, this will only be true for a
+server based on CGI (or something similar).
=item *
-C<psgi.async>: true if the server is calling the application in an asynchronous event loop. See L<PSGI Async extension|PSGI::Async>.
+C<psgi.async>: true if the server is calling the application in an
+asynchronous event loop. See L<PSGI Async extension|PSGI::Async>.
=back
-The server or the application can store their own data in the environment, too. The keys MUST contain at least one dot, and should be prefixed uniquely. The prefix C<psgi.> is reserved for use with the PSGI core implementation and other accepted extensions and MUST NOT be used otherwise. The environment MUST NOT contain the keys C<HTTP_CONTENT_TYPE> or C<HTTP_CONTENT_LENGTH> (use the versions without C<HTTP_>). The CGI keys (named without a period) MUST have a scalar variable containing strings. There are the following restrictions:
+The server or the application can store their own data in the
+environment, too. The keys MUST contain at least one dot, and should
+be prefixed uniquely. The prefix C<psgi.> is reserved for use with the
+PSGI core implementation and other accepted extensions and MUST NOT be
+used otherwise. The environment MUST NOT contain the keys
+C<HTTP_CONTENT_TYPE> or C<HTTP_CONTENT_LENGTH> (use the versions
+without C<HTTP_>). The CGI keys (named without a period) MUST have a
+scalar variable containing strings. There are the following
+restrictions:
=over 4
@@ -103,7 +146,8 @@ C<psgi.version> MUST be an array of integers.
=item *
-C<psgi.url_scheme> MUST either be a scalar variable containing a string C<http> or C<https>.
+C<psgi.url_scheme> MUST either be a scalar variable containing a
+string C<http> or C<https>.
=item *
@@ -131,15 +175,22 @@ The C<CONTENT_LENGTH>, if given, MUST consist of digits only.
=item *
-One of C<SCRIPT_NAME> or C<PATH_INFO> MUST be set. C<PATH_INFO> should be / if C<SCRIPT_NAME> is empty. C<SCRIPT_NAME> never should be /, but instead be empty.
+One of C<SCRIPT_NAME> or C<PATH_INFO> MUST be set. C<PATH_INFO> should
+be / if C<SCRIPT_NAME> is empty. C<SCRIPT_NAME> never should be /, but
+instead be empty.
=back
=head3 The Input Stream
-The input stream in C<psgi.input> is an IO::Handle-like object which streams the raw HTTP POST or PUT data. If it is a file handle then it MUST be opened in binary mode. The input stream MUST respond to C<read> and MAY implement C<seek>.
+The input stream in C<psgi.input> is an IO::Handle-like object which
+streams the raw HTTP POST or PUT data. If it is a file handle then it
+MUST be opened in binary mode. The input stream MUST respond to
+C<read> and MAY implement C<seek>.
-The built-in filehandle or IO::Handle based objects should work fine everywhere. Application developers SHOULD NOT inspect the type or class of the stream, but instead just call C<read> to duck type.
+The built-in filehandle or IO::Handle based objects should work fine
+everywhere. Application developers SHOULD NOT inspect the type or
+class of the stream, but instead just call C<read> to duck type.
=over 4
@@ -155,9 +206,12 @@ The built-in filehandle or IO::Handle based objects should work fine everywhere.
=head3 The Error Stream
-The error stream in C<psgi.errors> is an IO::Handle-like object to print errors. The error stream must implement C<print>.
+The error stream in C<psgi.errors> is an IO::Handle-like object to
+print errors. The error stream must implement C<print>.
-The built-in filehandle or IO::Handle based objects should work fine everywhere. Application developers SHOULD NOT inspect the type or class of the stream, but instead just call C<print> to duck type.
+The built-in filehandle or IO::Handle based objects should work fine
+everywhere. Application developers SHOULD NOT inspect the type or
+class of the stream, but instead just call C<print> to duck type.
=over 4
@@ -175,21 +229,32 @@ HTTP status code, is an integer and MUST be greater than or equal to 100.
=head4 Headers
-The header must be an array reference containing a pair of key and value. Its number of elements MUST be even. The header MUST NOT contain a C<Status> key, contain keys with C<:> or newlines in their name, contain keys that end in C<-> or C<_> but only contain keys that consist of letters, digits, C<_> or C<-> and start with a letter. The value of the header must be a scalar value that contains strings. The value string MUST NOT contain characters below chr(37).
+The header must be an array reference containing a pair of key and
+value. Its number of elements MUST be even. The header MUST NOT
+contain a C<Status> key, contain keys with C<:> or newlines in their
+name, contain keys that end in C<-> or C<_> but only contain keys that
+consist of letters, digits, C<_> or C<-> and start with a letter. The
+value of the header must be a scalar value that contains strings. The
+value string MUST NOT contain characters below chr(37).
-If the same key name appears multiple times in an array ref, those header lines MUST be sent to the client separately (e.g. multiple C<Set-Cookie> lines).
+If the same key name appears multiple times in an array ref, those
+header lines MUST be sent to the client separately (e.g. multiple
+C<Set-Cookie> lines).
=head4 Content-Type
-There MUST be a C<Content-Type> except when the C<Status> is 1xx, 204 or 304, in which case there MUST be none given.
+There MUST be a C<Content-Type> except when the C<Status> is 1xx, 204
+or 304, in which case there MUST be none given.
=head4 Content-Length
-There MUST NOT be a C<Content-Length> header when the C<Status> is 1xx, 204 or 304.
+There MUST NOT be a C<Content-Length> header when the C<Status> is
+1xx, 204 or 304.
=head4 Body
-The response body is returned from the application in one of following two types of scalar variable.
+The response body is returned from the application in one of following
+two types of scalar variable.
=over 4
@@ -206,7 +271,8 @@ An IO::Handle-like object or a built-in filehandle.
open my $body, "</path/to/file";
my $body = IO::File->new("/path/to/file");
-Implementors SHOULD NOT check if the type or class of body but instead just call C<getline> to iterate the body and call C<close> when done.
+Implementors SHOULD NOT check if the type or class of body but instead
+just call C<getline> to iterate the body and call C<close> when done.
=back
Oops, something went wrong.

0 comments on commit ff0e6de

Please sign in to comment.