| | 106 | def test_HTTP11_Timeout(self): |
|---|
| | 107 | if cherrypy.server.protocol_version != "HTTP/1.1": |
|---|
| | 108 | print "skipped ", |
|---|
| | 109 | return |
|---|
| | 110 | |
|---|
| | 111 | old_timeout = None |
|---|
| | 112 | try: |
|---|
| | 113 | httpserver = cherrypy.server.httpservers.keys()[0] |
|---|
| | 114 | old_timeout = httpserver.timeout |
|---|
| | 115 | except AttributeError: |
|---|
| | 116 | print "skipped ", |
|---|
| | 117 | return |
|---|
| | 118 | |
|---|
| | 119 | try: |
|---|
| | 120 | httpserver.timeout = 0.1 |
|---|
| | 121 | self.PROTOCOL = "HTTP/1.1" |
|---|
| | 122 | |
|---|
| | 123 | # Make an initial request |
|---|
| | 124 | conn = httplib.HTTPConnection(self.HOST, self.PORT) |
|---|
| | 125 | conn.auto_open = False |
|---|
| | 126 | conn.connect() |
|---|
| | 127 | conn.putrequest("GET", "/", skip_host=True) |
|---|
| | 128 | conn.putheader("Host", self.HOST) |
|---|
| | 129 | conn.endheaders() |
|---|
| | 130 | response = conn.response_class(conn.sock, method="GET") |
|---|
| | 131 | response.begin() |
|---|
| | 132 | self.assertEqual(response.status, 200) |
|---|
| | 133 | |
|---|
| | 134 | # Make a second request on the same socket |
|---|
| | 135 | conn._output('GET /hello HTTP/1.1') |
|---|
| | 136 | conn._output("Host: %s" % self.HOST) |
|---|
| | 137 | conn._send_output() |
|---|
| | 138 | response = conn.response_class(conn.sock, method="GET") |
|---|
| | 139 | response.begin() |
|---|
| | 140 | self.assertEqual(response.status, 200) |
|---|
| | 141 | |
|---|
| | 142 | # Wait for our socket timeout |
|---|
| | 143 | time.sleep(0.2) |
|---|
| | 144 | |
|---|
| | 145 | # Make another request on the same socket, which should error |
|---|
| | 146 | conn._output('GET /hello HTTP/1.1') |
|---|
| | 147 | conn._output("Host: %s" % self.HOST) |
|---|
| | 148 | conn._send_output() |
|---|
| | 149 | response = conn.response_class(conn.sock, method="GET") |
|---|
| | 150 | self.assertRaises(socket.error, response.begin) |
|---|
| | 151 | |
|---|
| | 152 | conn.close() |
|---|
| | 153 | finally: |
|---|
| | 154 | if old_timeout is not None: |
|---|
| | 155 | httpserver.timeout = old_timeout |
|---|
| | 156 | |
|---|