From 5df83a38282d8ddbc653859914eb49cad1c30494 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 4 Sep 2012 08:53:39 -0500 Subject: Add a 'format_http_headers' method This takes a HttpRequest object and grabs the HTTP headers out of it and pretty-prints them in a familiar format. This will come in handy if we want to log these when creating package FlagRequests, releng Tests, etc. in addition to already logging the IP address of the user posting the request. Signed-off-by: Dan McGee --- main/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'main') diff --git a/main/utils.py b/main/utils.py index 0b6849a..d12e5e1 100644 --- a/main/utils.py +++ b/main/utils.py @@ -53,6 +53,16 @@ def clear_cache_function(func, args, kwargs): key = cache_function_key(func, args, kwargs) cache.delete(key) + +def format_http_headers(request): + headers = sorted((k, v) for k, v in request.META.items() + if k.startswith('HTTP_')) + data = [] + for k, v in headers: + data.extend([k[5:].replace('_', '-').title(), ': ', v, '\n']) + return ''.join(data) + + # utility to make a pair of django choices make_choice = lambda l: [(str(m), str(m)) for m in l] -- cgit v1.2.3-24-g4f1b