Skip to content
Browse files

Don't put wsgi response headers in a dictionary to support repeated

headers with the same value (mainly important for Set-Cookie)
  • Loading branch information...
1 parent 7fda8c5 commit 33a587b0d5dc22c4f124734acca904759123a453 Ben Darnell committed Mar 22, 2010
Showing with 9 additions and 5 deletions.
  1. +9 −5 tornado/wsgi.py
View
14 tornado/wsgi.py
@@ -212,7 +212,7 @@ def __call__(self, request):
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 @@ def start_response(status, response_headers, exc_info=None):
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)

0 comments on commit 33a587b

Please sign in to comment.
Something went wrong with that request. Please try again.