Skip to content

Commit 5023d84

Browse files
author
Richard Jones
committed
handle connection loss when responding to web requests
1 parent 1bfc72d commit 5023d84

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ are given with the most recent entry first.
44
2006-??-?? 1.1.3
55
Feature:
66
- full timezone support (sf patch 1465296)
7+
- handle connection loss when responding to web requests
78

89

910
2006-04-27 1.1.2

roundup/cgi/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# $Id: client.py,v 1.225 2006-04-27 04:03:11 richard Exp $
1+
# $Id: client.py,v 1.226 2006-06-06 01:44:44 richard Exp $
22

33
"""WWW request handler (also used in the stand-alone server).
44
"""
55
__docformat__ = 'restructuredtext'
66

77
import base64, binascii, cgi, codecs, mimetypes, os
88
import random, re, rfc822, stat, time, urllib, urlparse
9-
import Cookie
9+
import Cookie, socket, errno
1010

1111
from roundup import roundupdb, date, hyperdb, password
1212
from roundup.cgi import templating, cgitb, TranslationService
@@ -821,7 +821,12 @@ def write(self, content):
821821
if not self.headers_done:
822822
self.header()
823823
if self.env['REQUEST_METHOD'] != 'HEAD':
824-
self.request.wfile.write(content)
824+
try:
825+
self.request.wfile.write(content)
826+
except socket.error, error:
827+
# the end-user has gone away
828+
if error.errno != errno.EPIPE:
829+
raise
825830

826831
def write_html(self, content):
827832
if not self.headers_done:
@@ -840,7 +845,12 @@ def write_html(self, content):
840845
content = content.encode(self.charset, 'xmlcharrefreplace')
841846

842847
# and write
843-
self.request.wfile.write(content)
848+
try:
849+
self.request.wfile.write(content)
850+
except socket.error, error:
851+
# the end-user has gone away
852+
if error.errno != errno.EPIPE:
853+
raise
844854

845855
def setHeader(self, header, value):
846856
'''Override a header to be returned to the user's browser.

0 commit comments

Comments
 (0)