NAME

Para::Frame::Request::Response - Represents the response page for a req

DESCRIPTION

TODO: Rewrite

Represents a page on a site with a specific URL.

Inherits from Para::Frame::File

During lookup or generation of the page, the URL of the page can change. We differ between the original requested URL, the resulting URL and an URL for the template used.

A Para::Frame::Request will create a Para::Frame::Site::Page object representing the response page.

A request can also create other Page objects for representing other pages for getting information about them or for generating pages for later use, maby not specificly copupled to the current request or session.

The distinction between Para::Frame::Request and Para::Frame::Site::Page are still a litle bit vauge. We should separate more clearly between the requested URL and the URL used for the response and the template used for the response.

Methods for generating the response page and accessing info about that page has been collected here.

A Site can answer under many hosts. The host of a Page vary with the request. The language given by the request is used also for actions and not just for the response page.

Each Request has one response Page object. It may first be a normal template and then change to generate an error page if action or template throw an exception. But it is still the same object.

I may change that so that a new Page object is created if there was a redirection to a new page.

Constructors

new

This constructor is usually called by Para::Frame::Request/set_response.

params:

  template => used in renderer->new

  req
  site
  language
  is_error_response
  umask
  url
  page
  renderer
  file_may_not_exist
  always_move

new_minimal

clone

desig

page

page_url_with_query

Returns a l<Para::Frame::URI> object.

page_url_path_with_query

Returns the full URL path as a string

page_url_path_with_query_and_reqnum

Returns the full URL path as a string

page_url_path_with_reqnum

Returns the full URL path as a string

req

is_error_response

  $resp->is_error_response

True if this is an error response

is_error

  $resp->is_error

True if this is an error response

is_no_error

  $resp->is_no_error

True if this is not an error response

set_is_error

  $resp->set_is_error()

  $resp->set_is_error(0)

headers

  $resp->headers

Returns: the http headers to be sent to the client as a list of listrefs of key/val pairs.

redirection

  $resp->redirection

Returns the page we will redirect to, or undef.

set_headers

  $resp->set_headers( [[$key,$val], [$key2,$val2], ... ] )

Same as /add_header, but replaces any existing headers.

set_header

  $resp->set_header( $key => $val )

Replaces any existing header with the same key.

Returns:

The number of changes

add_header

  $resp->add_header( [[$key,$val], [$key2,$val2], ... ] )

Adds one or more http response headers.

This sets headers to be used if this page is sent to the client. They can be changed until they are actually sent.

ctype

  $resp->ctype

Returns the PRELIMINARY content type to use in the http response, in the form of a Para::Frame::Request::Ctype object.

It will be initialized from the client request and may be changed before the response is sent back.

Especieally, it may be changed by the renderer before sending the http headers.

redirect

  $resp->redirect( $url )

  $resp->redirect( $url, $permanently_flag )

This is for redirecting to a page not handled by the paraframe.

The actual redirection will be done then all the jobs are finished. Error in the jobs could result in a redirection to an error page instead.

The $url should be a full url string starting with http: or https: or just the path under the curent host.

If $permanently_flag is true, sets the http header for indicating that the requested page permanently hase moved to this page.

For redirection to a TT page handled by the same paraframe daemon, use Para::Frame::Request/set_response_page.

set_http_status

  $resp->set_http_status( $status )

Used internally by /render_output for sending the http_status of the response page to the client.

send_output

  $resp->send_output

SENDER!

Sends the previously generated page to the client.

If the URL should change, sends a redirection header and stores the generated page in the session to be sent as a response to the future request to for the new URL.

Sends the headers followd by the page content.

If the content is in UTF8, sends the page in UTF8.

For large pages, sends the page in chunks.

send_http_output

  $resp->send_http_output

HTTP sender

Sends the previously generated page to the client.

forward

  $resp->forward( $url )

Should only be called AFTER the page has been generated. It's used by /send_output and should not be used by others.

$url must be a normalized url path

To request a forward, just use Para::Frame::Request/set_response_page before the page is generated.

To forward to a page not handled by the paraframe, use /redirect.

Will not forward if it's an ajax request or req dirconfig loadpage is 'no'.

Returns: true if the redirection was done

send_redirection

  $resp->send_redirection( $url )

SENDER!

Internally used by /forward for sending redirection headers to the client.

send_headers

  $resp->send_headers()

Used internally by /send_output for sending the HTTP headers to the client.

The headers themself are not sent in utf8...

send_stored_result

send_not_modified

  $resp->send_not_modified()

Just as send_output, but sends a header saying that the requested page has not been modified.

equals

set_content

set_sender

sender

renderer

  $resp->renderer

Sets the renderer if not yet defined, by calling /set_renderer.

Returns: the renderer to be used

set_renderer

  $resp->set_renderer( $renderer, \%args )

Sets the renderer to be uses. Renderer will be chosen from the first defined among

  1. the given $renderer
  2. $args->{'renderer'}
  3. $q->param('renderer')
  4. $req->dirconfig->{'renderer'}
  5. $resp->page->renderer()

The renderer should be either a) a renderer object, which will be returned as is b) the module class name of the renderer It will be looked for using the each of the appbases. Example; The renderer 'TT' will be looked for as Para::Frame::Renderer::TT

Loads and compiles the renderer if necessary

Sets renderer by calling new()

renerer_if_existing

render_output

  $resp->render_output()

  The caller must take care of C<$@> at failure

Returns:

   true if a response was sucessfully generated

   false if response not successfulle generated

last_modified

  $resp->last_modified()

This method should return the last modification date of the page in its rendered form.

This function currently only works for css and js pages.

TODO: Work with more than css and js pages.

For other pages, returns undef

query_string

SEE ALSO

Para::Frame