1. Jesper Noehr
  2. django-piston
  3. Issues
Issue #83 open

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

Anonymous created an issue

hi jespern,

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

see: http://code.google.com/apis/gdata/docs/2.0/basics.html

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.

thanks,

zhigang

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.

    thanks.

    zhigang

  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