Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

A pyramid plugin that rewrites the HTTP method based on a query-string parameter.

Project description

The pyramid_methodrewrite package is a pyramid plugin that adds a “tween” that rewrites the active HTTP method (as exposed via request.method) to the value provided in a query-string. The main reason for this is to allow clients to fake the use of HTTP methods beyond GET and POST (such as PUT and DELETE) that are behind non-compliant proxies, browsers, or other deficient software that limit which HTTP methods can be sent.

It does this by inspecting the query-string or POST data, and if a parameter named _method is found (the actual name is configurable) and is of the known set of HTTP methods, will override the active request’s .method attribute.

For example, the request:

GET /path/to/resource?_method=OPTIONS HTTP/1.1

Becomes equivalent (from the application’s point of view) to:

OPTIONS /path/to/resource HTTP/1.1

Installation

$ pip install pyramid-methodrewrite

Usage

Enable the tween either in your INI file via:

pyramid.includes = pyramid_methodrewrite

or in code in your package’s application initialization via:

def main(global_config, **settings):
  # ...
  config.include('pyramid_methodrewrite')
  # ...

Configuration

The following configuration settings can be set in your application’s main section:

  • methodrewrite.enabled: a boolean flag to control whether or not method rewriting should be enabled. Default: True.
  • methodrewrite.on: a list of incoming HTTP methods that will cause this tween to check the request parameters and potentially make the change. Defaults to (GET, POST).
  • methodrewrite.param: the name of the parameter that controls the requested method. Defaults to _method.
  • methodrewrite.to: list of acceptable HTTP methods that a request can be rewritten to. If set to empty, no restrictions will be made on mapping to acceptable or known methods. Defaults to pyramid_methodrewrite.HTTP_METHODS.

Note that all method names are always converted to upper case.

Project details


Download files

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

Files for pyramid_methodrewrite, version 0.2.1
Filename, size File type Python version Upload date Hashes
Filename, size pyramid_methodrewrite-0.2.1.tar.gz (5.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page