app: Make HTTP POST method emulation optional
For some applications, the HTTP method emulation for POST requests is undesirable, particularly when the request contains a large payload (e.g. file uploads, etc.). For these applications, this feature can be disabled by setting the `post_method_emulation` attribute of their application objects to `False`.master
parent
83971013d0
commit
71d00e4207
|
@ -50,6 +50,9 @@ class BaseApplication(object):
|
||||||
|
|
||||||
DEFAULT_CONFIG = {}
|
DEFAULT_CONFIG = {}
|
||||||
|
|
||||||
|
#: Enable HTTP method emulation for POST requests?
|
||||||
|
post_method_emulation = True
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.config = self.DEFAULT_CONFIG.copy()
|
self.config = self.DEFAULT_CONFIG.copy()
|
||||||
self.setup_routes()
|
self.setup_routes()
|
||||||
|
@ -163,6 +166,7 @@ class BaseApplication(object):
|
||||||
# Sometimes, hacky applications will try to "emulate" some HTTP
|
# Sometimes, hacky applications will try to "emulate" some HTTP
|
||||||
# methods like PUT or DELETE by specifying an _method parameter
|
# methods like PUT or DELETE by specifying an _method parameter
|
||||||
# in a POST request.
|
# in a POST request.
|
||||||
|
if self.post_method_emulation:
|
||||||
if request.method == 'POST' and '_method' in request.POST:
|
if request.method == 'POST' and '_method' in request.POST:
|
||||||
request.method = request.POST.pop('_method')
|
request.method = request.POST.pop('_method')
|
||||||
return request
|
return request
|
||||||
|
|
Loading…
Reference in New Issue