internal package Foswiki::Response

See PublishedAPI for packages intended to be used by Plugin and Contrib authors, or browse all packages.
See also Developing plugins, Developer's Bible, Technical Overview

internal package Foswiki::Response

Class to encapsulate response data.

Fields: * status - response status * headers - hashref to response headers * body - response body * cookies - hashref to response cookies

ClassMethod new() → $response

Constructs a Foswiki::Response object.

ObjectMethod status( $status ) → $status

Gets/Sets response status.
  • $status is a three digit code, optionally followed by a status string

ObjectMethod charset([$charset]) → $charset

Gets/Sets response charset. If not defined, defaults to ISO-8859-1, just like CGI.pm

ObjectMethod header(-type → $type,

-status => $status, -cookie => $cookie || \@cookies, -attachment => $attachName, -charset => $charset, -expires => $expires, -HeaderN => ValueN )

Sets response header. Resonably compatible with CGI. Doesn't support -nph, -target and -p3p.

ObjectMethod headers( { ... } ) → $headersHashRef

Gets/Sets all response headers. Keys are headers name and values are scalars for single-valued headers or arrayref for multivalued ones.

ObjectMethod getHeader( [ $name ] ) → $value

If called without parameters returns all present header names, otherwise returns a list (maybe with a single element) of values associated with $name.

ObjectMethod setDefaultHeaders( { $name → $value, ... } )

Sets the header corresponding to the key => value pairs passed in the hash, if the key doesn't already exist, otherwise does nothing. This ensures some default values are entered, but they can be overridden by plugins or other parts in the code.

ObjectMethod printHeaders()

Return a string of all headers, encoded as UTF8 and separated by CRLF

ObjectMethod deleteHeader($h1, $h2, ...)

Deletes headers whose names are passed.

ObjectMethod pushHeader( $name, $value )

Adds $value to list of values associated with header $name.

ObjectMethod cookies( [ \@cookies ] ) → @cookies

Gets/Sets response cookies. Parameter, if passed, must be an arrayref.

Elements may be CGI::Cookie objects or raw cookie strings.

WARNING: cookies set this way are not passed in redirects.

ObjectMethod body( [ $body ] ) → $body

Gets/Sets response body. Note that $body must be a byte string. Replaces the entire body; if you want to generate the body incrementally, use print instead.

Note that the $body returned is a byte string (utf8 encoded if print was used to create it)

ObjectMethod redirect( $uri, $status, $cookies |

-Location => $uri, -Status => $status, -Cookies => $cookies )

Populate object with redirect response headers.

$uri must be passed. Others are optional.

CGI Compatibility Note: It doesn't support -target or -nph

ObjectMethod print(...)

Add text content to the end of the body. Content may be unicode. Use $response->body() to output un-encoded byte strings / binary data

ObjectMethod outputHasStarted([$boolean])

Get/set the output-has-started flag. This is used by the Foswiki::Engine to separate header and body output. Once output has started, the headers cannot be changed (though the body can be modified)

Topic revision: r1 - 21 Nov 2014, ProjectContributor
This site is powered by FoswikiCopyright © by the contributing authors. All material on this site is the property of the contributing authors.
Ideas, requests, problems regarding WikiCMC? Send feedback