Skip to main content

Adaptable request interfaces.

Project description

The motivation for this package is to encourage the use of request type adaptation instead of depending on packages with request type definitions.

Instead of subclassing the request interface, we encourage an adaptation pattern:

>>> from repoze.bfg.interfaces import IRequest
>>> IGZipRequest = IRequest({'Accept-Encoding': 'gzip'})

An event handler listens for the INewRequest event and automatically marks the request with interfaces as needed to adapt the request to the request types that it may apply for.

To complete the example above, a request would come in with an HTTP environment like the following:

{‘Accept-Encoding’: ‘compress, gzip’}

Since we’ve previouly adapted the request to an accept-encoding of ‘gzip’, the adaptation machinery will mark the interface such that this environment will match the IGZipRequest interface.

This would be an alternative to subclassing, where we would manually have to set up an event listener that interprets the request environment and marks the request with the interface.

>>> class IGZipRequest(IRequest):
...     """Marker interface for requests for gzipped response."""

Credits

Stefan Eletzhofer <stefan.eletzhofer@inquant.de> and Malthe Borch <mborch@gmail.com>.

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

repoze.bfg.httprequest-0.1.tar.gz (4.9 kB view details)

Uploaded Source

File details

Details for the file repoze.bfg.httprequest-0.1.tar.gz.

File metadata

File hashes

Hashes for repoze.bfg.httprequest-0.1.tar.gz
Algorithm Hash digest
SHA256 3ebd60a459853f5813f86a8c09319bf1f854066cdefbe98fcc60fe93c63ffd82
MD5 4dabfde0c921a0d3fb2055f54c3de4ba
BLAKE2b-256 cff207cffbc3291038f6043f9fa428921b19327933b871deca0bb8e56f694cb5

See more details on using hashes here.

Supported by

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