document %header defaults, attributes, and changing
[perl/plp/.git] / lib / PLP / Fields.pm
index cd68e3655d6abf6d20c164d89fbcb8fed82383dc..27888babee8e2617ef733d4a7c215fb81ecf3175 100644 (file)
@@ -12,7 +12,7 @@ sub doit {
        # %get
        
        my $get = \%PLP::Script::get;
-       if (length $ENV{QUERY_STRING}){
+       if (defined $ENV{QUERY_STRING} and length $ENV{QUERY_STRING}){
                for (split /[&;]/, $ENV{QUERY_STRING}) {
                        my @keyval = split /=/, $_, 2;
                        PLP::Functions::DecodeURI(@keyval);
@@ -25,13 +25,10 @@ sub doit {
 
        tie %PLP::Script::post, 'PLP::Tie::Delay', 'PLP::Script::post', sub {
                my %post;
-               my $post;
-               
-               return \%post if $ENV{CONTENT_TYPE} !~
-                       m!^(?:application/x-www-form-urlencoded|$)!;
-               
-               $post = $PLP::read->($ENV{CONTENT_LENGTH}) if $ENV{CONTENT_LENGTH};
+               return \%post unless $ENV{CONTENT_TYPE} and $ENV{CONTENT_LENGTH} and
+                       $ENV{CONTENT_TYPE} =~ m!^(?:application/x-www-form-urlencoded|$)!;
                
+               my $post = $PLP::read->($ENV{CONTENT_LENGTH});
                return \%post unless defined $post and length $post;
                
                for (split /&/, $post) {
@@ -108,8 +105,18 @@ are B<not> automatically url-decoded.
 
 =item C<%header>, C<%headers>
 
-In this hash, you can set headers. Underscores are converted to normal minus
-signs, so you can leave out quotes. The hash is case insensitive: the case used
+This is a hash of HTTP headers to accompany the first output.
+By default it will contain C<X-PLP-Version> to identify the serving module,
+and C<Content-Type> set to C<text/html>.
+
+If STDOUT has been opened as :utf8,
+a C<charset=utf-8> attribute will automatically be added.
+This will not be possible with FastCGI
+because FCGI (as of version 0.74) does not support output layers.
+
+Headers can be added and/or changed as long as they have not yet been sent.
+Underscores in key names are converted to normal minus signs,
+so you can leave out quotes.  The hash is case insensitive: the case used
 when sending the headers is the one you used first. The following are equal:
 
     $header{CONTENT_TYPE}
@@ -117,6 +124,19 @@ when sending the headers is the one you used first. The following are equal:
     $header{Content_Type}
     $headers{CONTENT_type}
 
+If a value contains newlines, the header is repeated for each line:
+
+       $header{Allow} = "HEAD\nGET";  # equivalent to HEAD,GET
+
+For example, to send out a non-HTML text instead of the default HTML:
+
+    <:
+    $header{content_type} = 'text/plain';
+    use open ':std', ':utf8';
+    :>
+    This text should be prefixed by the following header:
+        Content-Type: text/plain; charset=utf-8
+
 =back
 
 =head1 AUTHOR