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 = {}
|
||||
|
||||
#: Enable HTTP method emulation for POST requests?
|
||||
post_method_emulation = True
|
||||
|
||||
def __init__(self):
|
||||
self.config = self.DEFAULT_CONFIG.copy()
|
||||
self.setup_routes()
|
||||
|
@ -163,8 +166,9 @@ class BaseApplication(object):
|
|||
# Sometimes, hacky applications will try to "emulate" some HTTP
|
||||
# methods like PUT or DELETE by specifying an _method parameter
|
||||
# in a POST request.
|
||||
if request.method == 'POST' and '_method' in request.POST:
|
||||
request.method = request.POST.pop('_method')
|
||||
if self.post_method_emulation:
|
||||
if request.method == 'POST' and '_method' in request.POST:
|
||||
request.method = request.POST.pop('_method')
|
||||
return request
|
||||
|
||||
def resolve_path(self, path_info):
|
||||
|
|
Loading…
Reference in New Issue