Skip to content

Instantly share code, notes, and snippets.

@pminkov
Created November 12, 2011 03:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pminkov/1359978 to your computer and use it in GitHub Desktop.
Save pminkov/1359978 to your computer and use it in GitHub Desktop.
Middleware class to simulate http errors.
from django.http import HttpResponse
IN_ERROR_MODE = False
class SimulatorMiddleware:
"""Modifies the HTTP response.
"""
def process_request(self, request):
if request.path.startswith('/http_simulate'):
return None
if IN_ERROR_MODE:
response = HttpResponse()
response.status_code = 408
return response
else:
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment