Skip to content

Instantly share code, notes, and snippets.

Created August 31, 2014 22:54
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?

With POST Tunneling, you are simply making a POST request act like a different type of request. Why is this neceesary? Because if you're using AJAX, most browsers only allow you to send GET or POST requests.

What needs to change?

  1. The headers sent with the request in the JavaScript file: headers: {'X_METHODOVERRIDE': 'DELETE'}
  2. Django middleware. So that the method is updated for requests that contain the X_METHODOVERRIDE header.


type: 'POST',
url: 'some_endpoint/',
data: {'your'': 'date'},
success: function(){ console.log("success"); }
error: function(){ console.log("error"); }
class TunnelingMiddleware(object):
def process_request(self, request):
if request.META.has_key('HTTP_X_METHODOVERRIDE'):
http_method = request.META['HTTP_X_METHODOVERRIDE']
if http_method.lower() == 'put':
request.method = 'PUT'
if http_method.lower() == 'delete':
request.method = 'DELETE'
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment