Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3945)

Unified Diff: client/cros/httpd.py

Issue 6877049: Cleanup http logs by handling broken pipe and connection reset by peer exceptions. (Closed) Base URL: ssh://gitrw.chromium.org:9222/autotest.git@master
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/cros/httpd.py
diff --git a/client/cros/httpd.py b/client/cros/httpd.py
index 0a3519aa21e10bfba6f3f46127813655c1428eb3..5f90f9a7c68f769d206aecf901aa17e17378a41a 100644
--- a/client/cros/httpd.py
+++ b/client/cros/httpd.py
@@ -11,12 +11,27 @@
http://localhost:nnnn/?status="Browser started!"
"""
-import cgi, logging, os, posixpath, SimpleHTTPServer, socket
+import cgi, errno, logging, os, posixpath, SimpleHTTPServer, socket
import socket, ssl, sys, threading, urllib, urlparse
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from SocketServer import BaseServer, ThreadingMixIn
+def _handle_http_errors(func):
+ """Decorator function for cleaner presentation of certain exceptions."""
+ def wrapper(self):
+ try:
+ func(self)
+ except IOError, e:
+ if e.errno == errno.EPIPE or e.errno == errno.ECONNRESET:
+ # Instead of dumping a stack trace, a single line is sufficient.
+ self.log_error(str(e))
+ else:
+ raise
+
+ return wrapper
+
+
class FormHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
"""Implements a form handler (for POST requests only) which simply
echoes the key=value parameters back in the response.
@@ -24,6 +39,7 @@ class FormHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
If the form submission is a file upload, the file will be written
to disk with the name contained in the 'filename' field.
"""
+ @_handle_http_errors
def do_POST(self):
form = cgi.FieldStorage(
fp=self.rfile,
@@ -104,6 +120,7 @@ class FormHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
logging.debug('URL %s not in watch list' % self.path)
+ @_handle_http_errors
def do_GET(self):
form = cgi.FieldStorage(
fp=self.rfile,
@@ -122,6 +139,11 @@ class FormHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
self._fire_event()
+ @_handle_http_errors
+ def do_HEAD(self):
+ SimpleHTTPServer.SimpleHTTPRequestHandler.do_HEAD(self)
+
+
class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
def __init__(self, server_address, HandlerClass):
HTTPServer.__init__(self, server_address, HandlerClass)
@@ -191,8 +213,8 @@ class SecureHTTPServer(ThreadingMixIn, HTTPServer):
class SecureHTTPRequestHandler(FormHandler):
def setup(self):
self.connection = self.request
- self.rfile = socket._fileobject(self.request, "rb", self.rbufsize)
- self.wfile = socket._fileobject(self.request, "wb", self.wbufsize)
+ self.rfile = socket._fileobject(self.request, 'rb', self.rbufsize)
+ self.wfile = socket._fileobject(self.request, 'wb', self.wbufsize)
class SecureHTTPListener(HTTPListener):
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698