From 4a0ba5c2e577e748768ac900a02e78b904c3c95f Mon Sep 17 00:00:00 2001 From: benoitc Date: Sat, 25 Feb 2012 20:10:42 +0100 Subject: [PATCH] fix upgrade header. close #298 . We were supposed to handled the upgrade header there but the way we extend the default headers imply we were sending 2 connections headers. Instead we are now testing if the upgrade header is present and keep it. --- gunicorn/http/wsgi.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/gunicorn/http/wsgi.py b/gunicorn/http/wsgi.py index 3b34f4cf..4cf833d8 100644 --- a/gunicorn/http/wsgi.py +++ b/gunicorn/http/wsgi.py @@ -157,6 +157,7 @@ class Response(object): self.headers_sent = False self.response_length = None self.sent = 0 + self.upgrade = False def force_close(self): self.must_close = True @@ -192,11 +193,11 @@ class Response(object): elif util.is_hoppish(name): if lname == "connection": # handle websocket - if value.lower().strip() != "upgrade": - continue - else: - # ignore hopbyhop headers - continue + if value.lower().strip() == "upgrade": + self.upgrade = True + + # ignore hopbyhop headers + continue self.headers.append((name.strip(), str(value).strip())) @@ -215,9 +216,14 @@ class Response(object): return True def default_headers(self): - connection = "keep-alive" - if self.should_close(): + # set the connection header + if self.upgrade: + connection = "upgrade" + elif self.should_close(): connection = "close" + else: + connection = "keepalive" + headers = [ "HTTP/%s.%s %s\r\n" % (self.req.version[0], self.req.version[1], self.status),