From ba85a0bc4ec54a124264327800c173e4dd5fc83a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 21 Jan 2016 21:58:57 +0000 Subject: Ignore IO errors writing CgiResults to clients as they may be gone away --- project2/cgi/cgiResultStatic.cpp | 9 +++++++-- project2/cgi/cgiResultWritable.cpp | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/project2/cgi/cgiResultStatic.cpp b/project2/cgi/cgiResultStatic.cpp index ab4ff43..8abeb05 100644 --- a/project2/cgi/cgiResultStatic.cpp +++ b/project2/cgi/cgiResultStatic.cpp @@ -15,8 +15,13 @@ class StaticToCgiResult : public TransformImpl { cr->header->addHeader("Last-Modified", buf); cr->header->addHeader("Etag", sc->getSHA1()); cr->header->addHeader("Cache-Control", "must-revalidate"); - cr->header->render(cr->stream); - sc->writeTo(cr->stream); + try { + cr->header->render(cr->stream); + sc->writeTo(cr->stream); + } + catch (const std::ios_base::failure &) { + // ignore (client may have gone away) + } } }; DECLARE_TRANSFORM(StaticToCgiResult); diff --git a/project2/cgi/cgiResultWritable.cpp b/project2/cgi/cgiResultWritable.cpp index 1364456..45e2a2a 100644 --- a/project2/cgi/cgiResultWritable.cpp +++ b/project2/cgi/cgiResultWritable.cpp @@ -30,8 +30,13 @@ class WritableToCgiResult : public TransformImpl { strftime(buf, sizeof(buf), "%a, %d %b %Y %T %z", &stm); cr->header->addHeader("Last-Modified", buf); } - cr->header->render(cr->stream); - wc->writeTo(cr->stream, cr->encoding, ec); + try { + cr->header->render(cr->stream); + wc->writeTo(cr->stream, cr->encoding, ec); + } + catch (const std::ios_base::failure &) { + // ignore (client may have gone away) + } } }; DECLARE_TRANSFORM(WritableToCgiResult); -- cgit v1.2.3