| 383 | | self.persistent = True |
|---|
| 384 | | conn = self.HTTP_CONN |
|---|
| 385 | | |
|---|
| 386 | | # Get a POST page with an error |
|---|
| 387 | | conn.putrequest("POST", "/err_before_read", skip_host=True) |
|---|
| 388 | | conn.putheader("Host", self.HOST) |
|---|
| 389 | | conn.putheader("Content-Type", "text/plain") |
|---|
| 390 | | conn.putheader("Content-Length", "1000") |
|---|
| 391 | | conn.putheader("Expect", "100-continue") |
|---|
| 392 | | conn.endheaders() |
|---|
| 393 | | response = conn.response_class(conn.sock, method="POST") |
|---|
| 394 | | |
|---|
| 395 | | # ...assert and then skip the 100 response |
|---|
| 396 | | version, status, reason = response._read_status() |
|---|
| 397 | | self.assertEqual(status, 100) |
|---|
| 398 | | while True: |
|---|
| 399 | | skip = response.fp.readline().strip() |
|---|
| 400 | | if not skip: |
|---|
| 401 | | break |
|---|
| 402 | | |
|---|
| 403 | | # ...send the body |
|---|
| 404 | | conn.send("x" * 1000) |
|---|
| 405 | | |
|---|
| 406 | | # ...get the final response |
|---|
| 407 | | response.begin() |
|---|
| 408 | | self.status, self.headers, self.body = webtest.shb(response) |
|---|
| 409 | | self.assertStatus(500) |
|---|
| 410 | | |
|---|
| 411 | | # Now try a working page with an Expect header... |
|---|
| 412 | | conn._output('POST /upload HTTP/1.1') |
|---|
| 413 | | conn._output("Host: %s" % self.HOST) |
|---|
| 414 | | conn._output("Content-Type: text/plain") |
|---|
| 415 | | conn._output("Content-Length: 17") |
|---|
| 416 | | conn._output("Expect: 100-continue") |
|---|
| 417 | | conn._send_output() |
|---|
| 418 | | response = conn.response_class(conn.sock, method="POST") |
|---|
| 419 | | |
|---|
| 420 | | # ...assert and then skip the 100 response |
|---|
| 421 | | version, status, reason = response._read_status() |
|---|
| 422 | | self.assertEqual(status, 100) |
|---|
| 423 | | while True: |
|---|
| 424 | | skip = response.fp.readline().strip() |
|---|
| 425 | | if not skip: |
|---|
| 426 | | break |
|---|
| 427 | | |
|---|
| 428 | | # ...send the body |
|---|
| 429 | | conn.send("I am a small file") |
|---|
| 430 | | |
|---|
| 431 | | # ...get the final response |
|---|
| 432 | | response.begin() |
|---|
| 433 | | self.status, self.headers, self.body = webtest.shb(response) |
|---|
| 434 | | self.assertStatus(200) |
|---|
| 435 | | self.assertBody("thanks for 'I am a small file' (text/plain)") |
|---|
| | 388 | # Test a max of 0 (the default) and then reset to what it was above. |
|---|
| | 389 | old_max = cherrypy.server.max_request_body_size |
|---|
| | 390 | for new_max in (0, old_max): |
|---|
| | 391 | cherrypy.server.max_request_body_size = new_max |
|---|
| | 392 | |
|---|
| | 393 | self.persistent = True |
|---|
| | 394 | conn = self.HTTP_CONN |
|---|
| | 395 | |
|---|
| | 396 | # Get a POST page with an error |
|---|
| | 397 | conn.putrequest("POST", "/err_before_read", skip_host=True) |
|---|
| | 398 | conn.putheader("Host", self.HOST) |
|---|
| | 399 | conn.putheader("Content-Type", "text/plain") |
|---|
| | 400 | conn.putheader("Content-Length", "1000") |
|---|
| | 401 | conn.putheader("Expect", "100-continue") |
|---|
| | 402 | conn.endheaders() |
|---|
| | 403 | response = conn.response_class(conn.sock, method="POST") |
|---|
| | 404 | |
|---|
| | 405 | # ...assert and then skip the 100 response |
|---|
| | 406 | version, status, reason = response._read_status() |
|---|
| | 407 | self.assertEqual(status, 100) |
|---|
| | 408 | while True: |
|---|
| | 409 | skip = response.fp.readline().strip() |
|---|
| | 410 | if not skip: |
|---|
| | 411 | break |
|---|
| | 412 | |
|---|
| | 413 | # ...send the body |
|---|
| | 414 | conn.send("x" * 1000) |
|---|
| | 415 | |
|---|
| | 416 | # ...get the final response |
|---|
| | 417 | response.begin() |
|---|
| | 418 | self.status, self.headers, self.body = webtest.shb(response) |
|---|
| | 419 | self.assertStatus(500) |
|---|
| | 420 | |
|---|
| | 421 | # Now try a working page with an Expect header... |
|---|
| | 422 | conn._output('POST /upload HTTP/1.1') |
|---|
| | 423 | conn._output("Host: %s" % self.HOST) |
|---|
| | 424 | conn._output("Content-Type: text/plain") |
|---|
| | 425 | conn._output("Content-Length: 17") |
|---|
| | 426 | conn._output("Expect: 100-continue") |
|---|
| | 427 | conn._send_output() |
|---|
| | 428 | response = conn.response_class(conn.sock, method="POST") |
|---|
| | 429 | |
|---|
| | 430 | # ...assert and then skip the 100 response |
|---|
| | 431 | version, status, reason = response._read_status() |
|---|
| | 432 | self.assertEqual(status, 100) |
|---|
| | 433 | while True: |
|---|
| | 434 | skip = response.fp.readline().strip() |
|---|
| | 435 | if not skip: |
|---|
| | 436 | break |
|---|
| | 437 | |
|---|
| | 438 | # ...send the body |
|---|
| | 439 | conn.send("I am a small file") |
|---|
| | 440 | |
|---|
| | 441 | # ...get the final response |
|---|
| | 442 | response.begin() |
|---|
| | 443 | self.status, self.headers, self.body = webtest.shb(response) |
|---|
| | 444 | self.assertStatus(200) |
|---|
| | 445 | self.assertBody("thanks for 'I am a small file' (text/plain)") |
|---|
| | 446 | conn.close() |
|---|