[wwwsearch-commits] r19188 - wwwsearch/ClientForm/trunk
jjlee at codespeak.net
jjlee at codespeak.net
Sun Oct 30 17:49:43 CET 2005
Author: jjlee
Date: Sun Oct 30 17:49:42 2005
New Revision: 19188
Modified:
wwwsearch/ClientForm/trunk/ClientForm.py
wwwsearch/ClientForm/trunk/test.py
Log:
Fix redirection of content-type header (Titus Brown)
Modified: wwwsearch/ClientForm/trunk/ClientForm.py
==============================================================================
--- wwwsearch/ClientForm/trunk/ClientForm.py (original)
+++ wwwsearch/ClientForm/trunk/ClientForm.py Sun Oct 30 17:49:42 2005
@@ -3091,5 +3091,12 @@
req_data = self._request_data()
req = request_class(req_data[0], req_data[1])
for key, val in req_data[2]:
- req.add_header(key, val)
+ add_hdr = req.add_header
+ if key.lower() == 'content-type':
+ try:
+ add_hdr = req.add_unredirected_header
+ except AttributeError:
+ # pre-2.4 and not using ClientCookie
+ pass
+ add_hdr(key, val)
return req
Modified: wwwsearch/ClientForm/trunk/test.py
==============================================================================
--- wwwsearch/ClientForm/trunk/test.py (original)
+++ wwwsearch/ClientForm/trunk/test.py Sun Oct 30 17:49:42 2005
@@ -2818,6 +2818,34 @@
reset_deprecations()
+class ContentTypeTests(TestCase):
+ def test_content_type(self):
+ import ClientForm
+ class OldStyleRequest:
+ def __init__(self, url, data=None, hdrs=None):
+ self.ah = self.auh = False
+ def add_header(self, key, val):
+ self.ah = True
+ class NewStyleRequest(OldStyleRequest):
+ def add_unredirected_header(self, key, val):
+ self.auh = True
+ class FakeForm(ClientForm.HTMLForm):
+ def __init__(self, hdr):
+ self.hdr = hdr
+ def _request_data(self):
+ return "http://example.com", "", [(self.hdr, "spam")]
+ for request_class, hdr, auh in [
+ (OldStyleRequest, "Foo", False),
+ (NewStyleRequest, "Foo", False),
+ (OldStyleRequest, "Content-type", False),
+ (NewStyleRequest, "Content-type", True),
+ ]:
+ form = FakeForm(hdr)
+ req = form._switch_click("request", request_class)
+ self.assertEqual(req.auh, auh)
+ self.assertEqual(req.ah, not auh)
+
+
def startswith(string, initial):
if len(initial) > len(string): return False
return string[:len(initial)] == initial
More information about the wwwsearch-commits
mailing list