From e6774204a6a81d3f8575b3f9f111cc2fe84f5e11 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Thu, 19 Feb 2015 20:01:05 -0600 Subject: [PATCH] app: Return an empty string for HEAD requests Some WSGI servers, e.g. Werkzeug, unconditionally attempt to iterate over the application response, even for HEAD requests. If `None` is returned, then the server will crash in this case, because it is not iterable. This commit alters the behavior of `milla.Application` to return an empty string, which is iterable and has the same effect of not sending a body. --- src/milla/app.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/milla/app.py b/src/milla/app.py index 7148fd2..80e7606 100644 --- a/src/milla/app.py +++ b/src/milla/app.py @@ -1,4 +1,4 @@ -# Copyright 2011 Dustin C. Hatch +# Copyright 2011, 2012, 2014, 2015 Dustin C. Hatch # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -112,7 +112,9 @@ class Application(object): if not start_response_wrapper.called: start_response(response.status, response.headerlist) - if not environ['REQUEST_METHOD'] == 'HEAD': + if environ['REQUEST_METHOD'] == 'HEAD': + return '' + else: return response.app_iter def _call_after(self, func):