Skip to content
Browse files

Add HTTPHeaders.copy()

Update HTTPHeaders to provide its own implementation of copy() that
returns a new HTTPHeaders object.  Previously calling copy() used the
underlying dict method, and returned a plain dict.
  • Loading branch information...
1 parent e101397 commit 4cf903bb950fc083dfccb69e01b3124d4c3a8bb2 @simpkins committed Feb 8, 2012
Showing with 9 additions and 0 deletions.
  1. +9 −0 tornado/httputil.py
View
9 tornado/httputil.py
@@ -154,6 +154,15 @@ def update(self, *args, **kwargs):
for k, v in dict(*args, **kwargs).iteritems():
self[k] = v
+ def copy(self):
+ # Create a new HTTPHeaders object.
+ # This will initialize the HTTPHeaders with the values in our dict, but
+ # won't populate the full lists as tracked by self._as_list
+ ret = HTTPHeaders(self)
+ # Update ret._as_list separately
+ ret._as_list = self._as_list.copy()
+ return ret
+
_NORMALIZED_HEADER_RE = re.compile(r'^[A-Z0-9][a-z0-9]*(-[A-Z0-9][a-z0-9]*)*$')
_normalized_headers = {}

0 comments on commit 4cf903b

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