# HG changeset patch # User Paul Boddie # Date 1342476090 -7200 # Node ID 4e984fd40300484ed4e4e4f25021475a86a8ad5a # Parent ead1f4d7710ef416d9438f6a52001f4ec49f9aff Prevent getHeader from raising an exception when a header is absent, returning None instead. diff -r ead1f4d7710e -r 4e984fd40300 MoinSupport.py --- a/MoinSupport.py Sun Jul 15 19:55:33 2012 +0200 +++ b/MoinSupport.py Tue Jul 17 00:01:30 2012 +0200 @@ -225,12 +225,21 @@ return request.path def getHeader(request, header_name, prefix=None): + + """ + Using the 'request', return the value of the header with the given + 'header_name', using the optional 'prefix' to obtain protocol-specific + headers if necessary. + + If no value is found for the given 'header_name', None is returned. + """ + if hasattr(request, "getHeader"): return request.getHeader(header_name) elif hasattr(request, "headers"): - return request.headers[header_name] + return request.headers.get(header_name) else: - return request.env[(prefix and prefix + "_" or "") + header_name.upper()] + return request.env.get((prefix and prefix + "_" or "") + header_name.upper()) # Content/media type and preferences support.