Use X-HTTP-Method-Override to override PUT and DELETE

Issue #83 open
Anonymous created an issue

hi jespern,

Can we consider implementing the X-HTTP-Method-Override mechnism?


As I searched, most libraries haven't support http PUT/DELETE yet.

Thanks for the excellent work. I find this library fits best the REST concept.



Comments (5)

  1. Jesper Noehr repo owner
    • changed status to open

    Hi Zhigang,

    Sure, that's reasonable. Someone has earlier suggested overriding methods with _method={PUT,DELETE} in the URL, which is awful. I can agree to X-HTTP-Method-Override.

    Do you feel like implementing it yourself?

  2. Anonymous

    I find piston is really designed great, I'm still learning it. I'll try implement if my project progress well.



  3. sandy lerman

    I'm using some middleware to take care of this. Something like:

    class x_http_methodoverride_middleware():
        def process_request(self, request):
            if 'HTTP_X_HTTP_METHODOVERRIDE' in request.META:
                newMethod = request.META['HTTP_X_HTTP_METHODOVERRIDE']
                if 'PUT' == newMethod.upper():
                    request.method = 'PUT'
                    request.META['REQUEST_METHOD'] = 'PUT'
                    request.PUT = request.POST                
                if 'DELETE' == newMethod.upper() or 'DEL' == newMethod.upper():
                    request.method = 'DELETE'
                    request.META['REQUEST_METHOD'] = 'DELETE'
                    request.DELETE = request.POST
  4. Log in to comment