From: Ben Darnell Date: Mon, 22 Mar 2010 23:35:05 +0000 (-0700) Subject: Don't put wsgi response headers in a dictionary to support repeated X-Git-Tag: v1.0.0~73^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=33a587b0d5dc22c4f124734acca904759123a453;p=thirdparty%2Ftornado.git Don't put wsgi response headers in a dictionary to support repeated headers with the same value (mainly important for Set-Cookie) --- diff --git a/tornado/wsgi.py b/tornado/wsgi.py index fca3b35f6..797911219 100644 --- a/tornado/wsgi.py +++ b/tornado/wsgi.py @@ -212,7 +212,7 @@ class WSGIContainer(object): data = {} def start_response(status, response_headers, exc_info=None): data["status"] = status - data["headers"] = HTTPHeaders(response_headers) + data["headers"] = response_headers response = self.wsgi_application( WSGIContainer.environ(request), start_response) body = "".join(response) @@ -222,13 +222,17 @@ class WSGIContainer(object): status_code = int(data["status"].split()[0]) headers = data["headers"] + header_set = set(k.lower() for (k,v) in headers) body = escape.utf8(body) - headers["Content-Length"] = str(len(body)) - headers.setdefault("Content-Type", "text/html; charset=UTF-8") - headers.setdefault("Server", "TornadoServer/0.1") + if "content-length" not in header_set: + headers.append(("Content-Length", str(len(body)))) + if "content-type" not in header_set: + headers.append(("Content-Type", "text/html; charset=UTF-8")) + if "server" not in header_set: + headers.append(("Server", "TornadoServer/0.1")) parts = ["HTTP/1.1 " + data["status"] + "\r\n"] - for key, value in headers.iteritems(): + for key, value in headers: parts.append(escape.utf8(key) + ": " + escape.utf8(value) + "\r\n") parts.append("\r\n") parts.append(body)