Last active
May 18, 2017 21:30
-
-
Save dashdanw/d00a3a652a10bb434bae5ce4a1bb9f23 to your computer and use it in GitHub Desktop.
Django HyperText Coffee Pot Control Protocol Middleware Implementation (HTCPCP)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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