Skip to content

Instantly share code, notes, and snippets.

@dashdanw
Last active May 18, 2017 21:30
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 dashdanw/d00a3a652a10bb434bae5ce4a1bb9f23 to your computer and use it in GitHub Desktop.
Save dashdanw/d00a3a652a10bb434bae5ce4a1bb9f23 to your computer and use it in GitHub Desktop.
Django HyperText Coffee Pot Control Protocol Middleware Implementation (HTCPCP)
#implements HTCPCP as per RFC 2324 https://www.ietf.org/rfc/rfc2324.txt
from django.http import HttpResponse
class HTCPCPMiddleware(object):
coffee_list = [
'/coffee/black/',
'/coffee/espresso/'
]
coffee_methods = [
'BREW',
'WHEN'
]
def process_request(self, request):
if request.path not in self.coffee_list and request.method not in self.coffee_methods:
return
if request.path not in self.coffee_list:
return HttpResponse("I'm a teapot.", status=418)
if request.path in self.coffee_list and request.method == 'BREW':
return HttpResponse("Say WHEN . . . ", status=100)
if request.path in self.coffee_list and request.method == 'WHEN':
return HttpResponse("Mmmmmmm coffee!", status=201)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment