| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import BaseHTTPServer | 5 import BaseHTTPServer |
| 6 import errno | 6 import errno |
| 7 import json | 7 import json |
| 8 import optparse | 8 import optparse |
| 9 import os | 9 import os |
| 10 import re | 10 import re |
| 11 import socket | 11 import socket |
| 12 import SocketServer | 12 import SocketServer |
| 13 import struct | 13 import struct |
| 14 import sys | 14 import sys |
| 15 import warnings | 15 import warnings |
| 16 | 16 |
| 17 import tlslite.errors |
| 18 |
| 17 # Ignore deprecation warnings, they make our output more cluttered. | 19 # Ignore deprecation warnings, they make our output more cluttered. |
| 18 warnings.filterwarnings("ignore", category=DeprecationWarning) | 20 warnings.filterwarnings("ignore", category=DeprecationWarning) |
| 19 | 21 |
| 20 if sys.platform == 'win32': | 22 if sys.platform == 'win32': |
| 21 import msvcrt | 23 import msvcrt |
| 22 | 24 |
| 23 # Using debug() seems to cause hangs on XP: see http://crbug.com/64515. | 25 # Using debug() seems to cause hangs on XP: see http://crbug.com/64515. |
| 24 debug_output = sys.stderr | 26 debug_output = sys.stderr |
| 25 def debug(string): | 27 def debug(string): |
| 26 debug_output.write(string + "\n") | 28 debug_output.write(string + "\n") |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 66 |
| 65 | 67 |
| 66 class BrokenPipeHandlerMixIn: | 68 class BrokenPipeHandlerMixIn: |
| 67 """Allows the server to deal with "broken pipe" errors (which happen if the | 69 """Allows the server to deal with "broken pipe" errors (which happen if the |
| 68 browser quits with outstanding requests, like for the favicon). This mix-in | 70 browser quits with outstanding requests, like for the favicon). This mix-in |
| 69 requires the class to derive from SocketServer.BaseServer and not override its | 71 requires the class to derive from SocketServer.BaseServer and not override its |
| 70 handle_error() method. """ | 72 handle_error() method. """ |
| 71 | 73 |
| 72 def handle_error(self, request, client_address): | 74 def handle_error(self, request, client_address): |
| 73 value = sys.exc_info()[1] | 75 value = sys.exc_info()[1] |
| 76 if isinstance(value, tlslite.errors.TLSClosedConnectionError): |
| 77 print "testserver.py: Closed connection" |
| 78 return |
| 74 if isinstance(value, socket.error): | 79 if isinstance(value, socket.error): |
| 75 err = value.args[0] | 80 err = value.args[0] |
| 76 if sys.platform in ('win32', 'cygwin'): | 81 if sys.platform in ('win32', 'cygwin'): |
| 77 # "An established connection was aborted by the software in your host." | 82 # "An established connection was aborted by the software in your host." |
| 78 pipe_err = 10053 | 83 pipe_err = 10053 |
| 79 else: | 84 else: |
| 80 pipe_err = errno.EPIPE | 85 pipe_err = errno.EPIPE |
| 81 if err == pipe_err: | 86 if err == pipe_err: |
| 82 print "testserver.py: Broken pipe" | 87 print "testserver.py: Broken pipe" |
| 83 return | 88 return |
| 89 if err == errno.ECONNRESET: |
| 90 print "testserver.py: Connection reset by peer" |
| 91 return |
| 84 SocketServer.BaseServer.handle_error(self, request, client_address) | 92 SocketServer.BaseServer.handle_error(self, request, client_address) |
| 85 | 93 |
| 86 | 94 |
| 87 class StoppableHTTPServer(BaseHTTPServer.HTTPServer): | 95 class StoppableHTTPServer(BaseHTTPServer.HTTPServer): |
| 88 """This is a specialization of BaseHTTPServer to allow it | 96 """This is a specialization of BaseHTTPServer to allow it |
| 89 to be exited cleanly (by setting its "stop" member to True).""" | 97 to be exited cleanly (by setting its "stop" member to True).""" |
| 90 | 98 |
| 91 def serve_forever(self): | 99 def serve_forever(self): |
| 92 self.stop = False | 100 self.stop = False |
| 93 self.nonce_time = None | 101 self.nonce_time = None |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 fd = msvcrt.open_osfhandle(self.options.startup_pipe, 0) | 249 fd = msvcrt.open_osfhandle(self.options.startup_pipe, 0) |
| 242 else: | 250 else: |
| 243 fd = self.options.startup_pipe | 251 fd = self.options.startup_pipe |
| 244 startup_pipe = os.fdopen(fd, "w") | 252 startup_pipe = os.fdopen(fd, "w") |
| 245 # First write the data length as an unsigned 4-byte value. This | 253 # First write the data length as an unsigned 4-byte value. This |
| 246 # is _not_ using network byte ordering since the other end of the | 254 # is _not_ using network byte ordering since the other end of the |
| 247 # pipe is on the same machine. | 255 # pipe is on the same machine. |
| 248 startup_pipe.write(struct.pack('=L', server_data_len)) | 256 startup_pipe.write(struct.pack('=L', server_data_len)) |
| 249 startup_pipe.write(server_data_json) | 257 startup_pipe.write(server_data_json) |
| 250 startup_pipe.close() | 258 startup_pipe.close() |
| OLD | NEW |