Changeset 1474
- Timestamp:
- 12/07/06 20:04:57
- Files:
-
- trunk/cherrypy/test/test_conn.py (modified) (10 diffs)
- trunk/cherrypy/test/webtest.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/test/test_conn.py
r1465 r1474 63 63 class ConnectionTests(helper.CPWebCase): 64 64 65 def connect_persistent(self, auto_open=False):66 """Set our HTTP_CONN to an instance so it persists between requests."""67 if self.scheme == "https":68 self.HTTP_CONN = httplib.HTTPSConnection(self.HOST, self.PORT)69 else:70 self.HTTP_CONN = httplib.HTTPConnection(self.HOST, self.PORT)71 # Automatically re-connect?72 self.HTTP_CONN.auto_open = auto_open73 self.HTTP_CONN.connect()74 return self.HTTP_CONN75 76 65 def test_HTTP11(self): 77 66 if cherrypy.server.protocol_version != "HTTP/1.1": … … 81 70 self.PROTOCOL = "HTTP/1.1" 82 71 83 self. connect_persistent()72 self.persistent = True 84 73 85 74 # Make the first request and assert there's no "Connection: close". … … 117 106 self.PROTOCOL = "HTTP/1.1" 118 107 119 self. connect_persistent()108 self.persistent = True 120 109 121 110 # Make the first request and assert there's no "Connection: close". … … 175 164 176 165 # Make an initial request 177 conn = self.connect_persistent() 166 self.persistent = True 167 conn = self.HTTP_CONN 178 168 conn.putrequest("GET", "/", skip_host=True) 179 169 conn.putheader("Host", self.HOST) … … 218 208 219 209 # Make another request on a new socket, which should work 220 conn = self.connect_persistent() 210 self.persistent = True 211 conn = self.HTTP_CONN 221 212 conn.putrequest("GET", "/", skip_host=True) 222 213 conn.putheader("Host", self.HOST) … … 239 230 240 231 # Test pipelining. httplib doesn't support this directly. 241 conn = self.connect_persistent() 232 self.persistent = True 233 conn = self.HTTP_CONN 242 234 243 235 # Put request 1 … … 275 267 self.PROTOCOL = "HTTP/1.1" 276 268 277 conn = self.connect_persistent() 269 self.persistent = True 270 conn = self.HTTP_CONN 278 271 279 272 # Try a page without an Expect request header first. … … 326 319 327 320 # Set our HTTP_CONN to an instance so it persists between requests. 328 self.connect_persistent() 321 self.persistent = True 322 conn = self.HTTP_CONN 329 323 330 324 # Make the first request and assert there's no "Connection: close". … … 362 356 363 357 # Set our HTTP_CONN to an instance so it persists between requests. 364 if self.scheme == "https": 365 conn = httplib.HTTPSConnection(self.HOST, self.PORT) 366 else: 367 conn = httplib.HTTPConnection(self.HOST, self.PORT) 358 self.persistent = True 359 conn = self.HTTP_CONN 368 360 369 361 # Try a normal chunked request (with extensions) … … 415 407 416 408 # Test a keep-alive HTTP/1.0 request. 417 self. connect_persistent()409 self.persistent = True 418 410 419 411 self.getPage("/page3", headers=[("Connection", "Keep-Alive")]) trunk/cherrypy/test/webtest.py
r1405 r1474 142 142 HTTP_CONN = httplib.HTTPConnection 143 143 PROTOCOL = "HTTP/1.1" 144 145 def set_persistent(self, on=True, auto_open=False): 146 """Make our HTTP_CONN persistent (or not). 147 148 If the 'on' argument is True (the default), then self.HTTP_CONN 149 will be set to an instance of httplib.HTTPConnection (or HTTPS 150 if self.scheme is "https"). This will then persist across requests. 151 152 We only allow for a single open connection, so if you call this 153 and we currently have an open connection, it will be closed. 154 """ 155 try: 156 self.HTTP_CONN.close() 157 except (TypeError, AttributeError): 158 pass 159 160 if self.scheme == "https": 161 cls = httplib.HTTPSConnection 162 else: 163 cls = httplib.HTTPConnection 164 165 if on: 166 self.HTTP_CONN = cls(self.HOST, self.PORT) 167 # Automatically re-connect? 168 self.HTTP_CONN.auto_open = auto_open 169 self.HTTP_CONN.connect() 170 else: 171 self.HTTP_CONN = cls 172 173 def _get_persistent(self): 174 return hasattr(self.HTTP_CONN, "__class__") 175 def _set_persistent(self, on=True): 176 self.set_persistent(on) 177 persistent = property(_get_persistent, _set_persistent) 144 178 145 179 def getPage(self, url, headers=None, method="GET", body=None, protocol=None):

