| 211 | | old_timeout = None |
|---|
| | 215 | self.PROTOCOL = "HTTP/1.1" |
|---|
| | 216 | |
|---|
| | 217 | # Make an initial request |
|---|
| | 218 | self.persistent = True |
|---|
| | 219 | conn = self.HTTP_CONN |
|---|
| | 220 | conn.putrequest("GET", "/timeout?t=%s" % timeout, skip_host=True) |
|---|
| | 221 | conn.putheader("Host", self.HOST) |
|---|
| | 222 | conn.endheaders() |
|---|
| | 223 | response = conn.response_class(conn.sock, method="GET") |
|---|
| | 224 | response.begin() |
|---|
| | 225 | self.assertEqual(response.status, 200) |
|---|
| | 226 | self.body = response.read() |
|---|
| | 227 | self.assertBody("0.1") |
|---|
| | 228 | |
|---|
| | 229 | # Make a second request on the same socket |
|---|
| | 230 | conn._output('GET /hello HTTP/1.1') |
|---|
| | 231 | conn._output("Host: %s" % self.HOST) |
|---|
| | 232 | conn._send_output() |
|---|
| | 233 | response = conn.response_class(conn.sock, method="GET") |
|---|
| | 234 | response.begin() |
|---|
| | 235 | self.assertEqual(response.status, 200) |
|---|
| | 236 | self.body = response.read() |
|---|
| | 237 | self.assertBody("Hello, world!") |
|---|
| | 238 | |
|---|
| | 239 | # Wait for our socket timeout |
|---|
| | 240 | time.sleep(timeout * 10) |
|---|
| | 241 | |
|---|
| | 242 | # Make another request on the same socket, which should error |
|---|
| | 243 | conn._output('GET /hello HTTP/1.1') |
|---|
| | 244 | conn._output("Host: %s" % self.HOST) |
|---|
| | 245 | conn._send_output() |
|---|
| | 246 | response = conn.response_class(conn.sock, method="GET") |
|---|
| 213 | | httpserver = cherrypy.server.httpserver |
|---|
| 214 | | old_timeout = httpserver.timeout |
|---|
| 215 | | except (AttributeError, IndexError): |
|---|
| 216 | | print "skipped ", |
|---|
| 217 | | return |
|---|
| 218 | | |
|---|
| 219 | | try: |
|---|
| 220 | | httpserver.timeout = timeout |
|---|
| 221 | | self.PROTOCOL = "HTTP/1.1" |
|---|
| 222 | | |
|---|
| 223 | | # Make an initial request |
|---|
| 224 | | self.persistent = True |
|---|
| 225 | | conn = self.HTTP_CONN |
|---|
| 226 | | conn.putrequest("GET", "/", skip_host=True) |
|---|
| 227 | | conn.putheader("Host", self.HOST) |
|---|
| 228 | | conn.endheaders() |
|---|
| 229 | | response = conn.response_class(conn.sock, method="GET") |
|---|
| 231 | | self.assertEqual(response.status, 200) |
|---|
| 232 | | self.body = response.read() |
|---|
| 233 | | self.assertBody(pov) |
|---|
| 234 | | |
|---|
| 235 | | # Make a second request on the same socket |
|---|
| 236 | | conn._output('GET /hello HTTP/1.1') |
|---|
| 237 | | conn._output("Host: %s" % self.HOST) |
|---|
| 238 | | conn._send_output() |
|---|
| 239 | | response = conn.response_class(conn.sock, method="GET") |
|---|
| 240 | | response.begin() |
|---|
| 241 | | self.assertEqual(response.status, 200) |
|---|
| 242 | | self.body = response.read() |
|---|
| 243 | | self.assertBody("Hello, world!") |
|---|
| 244 | | |
|---|
| 245 | | # Wait for our socket timeout |
|---|
| 246 | | time.sleep(timeout * 2) |
|---|
| 247 | | |
|---|
| 248 | | # Make another request on the same socket, which should error |
|---|
| 249 | | conn._output('GET /hello HTTP/1.1') |
|---|
| 250 | | conn._output("Host: %s" % self.HOST) |
|---|
| 251 | | conn._send_output() |
|---|
| 252 | | response = conn.response_class(conn.sock, method="GET") |
|---|
| 253 | | try: |
|---|
| 254 | | response.begin() |
|---|
| 255 | | except: |
|---|
| 256 | | if not isinstance(sys.exc_info()[1], |
|---|
| 257 | | (socket.error, httplib.BadStatusLine)): |
|---|
| 258 | | self.fail("Writing to timed out socket didn't fail" |
|---|
| 259 | | " as it should have: %s" % sys.exc_info()[1]) |
|---|
| 260 | | else: |
|---|
| | 249 | except: |
|---|
| | 250 | if not isinstance(sys.exc_info()[1], |
|---|
| | 251 | (socket.error, httplib.BadStatusLine)): |
|---|
| 262 | | " as it should have: %s" % |
|---|
| 263 | | response.read()) |
|---|
| 264 | | |
|---|
| 265 | | conn.close() |
|---|
| 266 | | |
|---|
| 267 | | # Make another request on a new socket, which should work |
|---|
| 268 | | self.persistent = True |
|---|
| 269 | | conn = self.HTTP_CONN |
|---|
| 270 | | conn.putrequest("GET", "/", skip_host=True) |
|---|
| 271 | | conn.putheader("Host", self.HOST) |
|---|
| 272 | | conn.endheaders() |
|---|
| 273 | | response = conn.response_class(conn.sock, method="GET") |
|---|
| 274 | | response.begin() |
|---|
| 275 | | self.assertEqual(response.status, 200) |
|---|
| 276 | | self.body = response.read() |
|---|
| 277 | | self.assertBody(pov) |
|---|
| 278 | | |
|---|
| 279 | | # Make another request on the same socket, |
|---|
| 280 | | # but timeout on the headers |
|---|
| 281 | | conn.send('GET /hello HTTP/1.1') |
|---|
| 282 | | # Wait for our socket timeout |
|---|
| 283 | | time.sleep(timeout * 2) |
|---|
| 284 | | response = conn.response_class(conn.sock, method="GET") |
|---|
| 285 | | response.begin() |
|---|
| 286 | | self.assertEqual(response.status, 408) |
|---|
| 287 | | conn.close() |
|---|
| 288 | | |
|---|
| 289 | | # Retry the request on a new connection, which should work |
|---|
| 290 | | self.persistent = True |
|---|
| 291 | | conn = self.HTTP_CONN |
|---|
| 292 | | conn.putrequest("GET", "/", skip_host=True) |
|---|
| 293 | | conn.putheader("Host", self.HOST) |
|---|
| 294 | | conn.endheaders() |
|---|
| 295 | | response = conn.response_class(conn.sock, method="GET") |
|---|
| 296 | | response.begin() |
|---|
| 297 | | self.assertEqual(response.status, 200) |
|---|
| 298 | | self.body = response.read() |
|---|
| 299 | | self.assertBody(pov) |
|---|
| 300 | | conn.close() |
|---|
| 301 | | finally: |
|---|
| 302 | | if old_timeout is not None: |
|---|
| 303 | | httpserver.timeout = old_timeout |
|---|
| | 253 | " as it should have: %s" % sys.exc_info()[1]) |
|---|
| | 254 | else: |
|---|
| | 255 | self.fail("Writing to timed out socket didn't fail" |
|---|
| | 256 | " as it should have: %s" % |
|---|
| | 257 | response.read()) |
|---|
| | 258 | |
|---|
| | 259 | conn.close() |
|---|
| | 260 | |
|---|
| | 261 | # Make another request on a new socket, which should work |
|---|
| | 262 | self.persistent = True |
|---|
| | 263 | conn = self.HTTP_CONN |
|---|
| | 264 | conn.putrequest("GET", "/", skip_host=True) |
|---|
| | 265 | conn.putheader("Host", self.HOST) |
|---|
| | 266 | conn.endheaders() |
|---|
| | 267 | response = conn.response_class(conn.sock, method="GET") |
|---|
| | 268 | response.begin() |
|---|
| | 269 | self.assertEqual(response.status, 200) |
|---|
| | 270 | self.body = response.read() |
|---|
| | 271 | self.assertBody(pov) |
|---|
| | 272 | |
|---|
| | 273 | # Make another request on the same socket, |
|---|
| | 274 | # but timeout on the headers |
|---|
| | 275 | conn.send('GET /hello HTTP/1.1') |
|---|
| | 276 | # Wait for our socket timeout |
|---|
| | 277 | time.sleep(timeout * 10) |
|---|
| | 278 | response = conn.response_class(conn.sock, method="GET") |
|---|
| | 279 | response.begin() |
|---|
| | 280 | self.assertEqual(response.status, 408) |
|---|
| | 281 | conn.close() |
|---|
| | 282 | |
|---|
| | 283 | # Retry the request on a new connection, which should work |
|---|
| | 284 | self.persistent = True |
|---|
| | 285 | conn = self.HTTP_CONN |
|---|
| | 286 | conn.putrequest("GET", "/", skip_host=True) |
|---|
| | 287 | conn.putheader("Host", self.HOST) |
|---|
| | 288 | conn.endheaders() |
|---|
| | 289 | response = conn.response_class(conn.sock, method="GET") |
|---|
| | 290 | response.begin() |
|---|
| | 291 | self.assertEqual(response.status, 200) |
|---|
| | 292 | self.body = response.read() |
|---|
| | 293 | self.assertBody(pov) |
|---|
| | 294 | conn.close() |
|---|