Skip to main content

Subrequests for Zope2

Project description

Overview

plone.subrequest provides a mechanism for issuing subrequests under Zope2.

Installation

Plone 4

An entry point is provided so no special installation is required past adding plone.subrequest to your instance’s eggs.

Zope 2.12 without Plone

Load this package’s ZCML in the usual manner.

Zope 2.10

You must install ZPublisherEventsBackport to use this package with Zope 2.10 and load both package’s ZCML. The tests require Zope 2.12 / Python 2.6 so will not run.

Usage

Basic usage

Call subrequest(url), it returns a response object.

>>> from plone.subrequest import subrequest
>>> response = subrequest('/folder1/@@url')

The output of the response is normally written to the response body.

>>> response.body
'http://nohost/folder1'

Be aware that some code may call response.write(data)

>>> response = subrequest('/@@response-write')
>>> response.stdout.getvalue()
'Some data.\nSome more data.\n'

so it’s usually best to retrieve the output with:

>>> result = response.body or response.stdout.getvalue()

Relative paths

Relative paths are resolved relative to the parent request’s location:

>>> request = traverse('/folder1/@@test')
>>> response = subrequest('folder1A/@@url')
>>> response.body
'http://nohost/folder1/folder1A'

This takes account of default view’s url.

>>> request = traverse('/folder1')
>>> request['URL']
'http://nohost/folder1/@@test'
>>> response = subrequest('folder1A/@@url')
>>> response.body
'http://nohost/folder1/folder1A'

Virtual hosting

When virtual hosting is used, absolute paths are traversed from the virtual host root.

>>> request = traverse('/VirtualHostBase/http/example.org:80/folder1/VirtualHostRoot/')
>>> response = subrequest('/folder1A/@@url')
>>> response.body
'http://example.org/folder1A'

Specifying the root

You may also set the root object explicitly

>>> app = layer['app']
>>> response = subrequest('/folder1A/@@url', root=app.folder1)
>>> response.body
'http://nohost/folder1/folder1A'

Error responses

Subrequests may not be found.

>>> response = subrequest('/not-found')
>>> response.status
404

Or might raise an error.

>>> response = subrequest('/@@error')
>>> response.status
500

So check for the expected status.

>>> response = subrequest('/')
>>> response.status
200

Changelog

1.1 - 2010-08-14

  • Virtual hosting, relative url and error response support. [elro]

1.0 - 2010-07-28

  • Initial release. [elro]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plone.subrequest-1.1.tar.gz (14.4 kB view details)

Uploaded Source

File details

Details for the file plone.subrequest-1.1.tar.gz.

File metadata

File hashes

Hashes for plone.subrequest-1.1.tar.gz
Algorithm Hash digest
SHA256 2f09ae3e7a32a4bc6fa3f863da404e6b31262896e4468e17d2acab811f2976e0
MD5 5d90398216bc07b5e918b8ff06058f71
BLAKE2b-256 99355abc2d04715f1806c45ae3d5b170060f235fe34991bb63f226f8a70e6c38

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page