Send a template-based response in case of server connection timeouts.
authorFabian Keil <fk@fabiankeil.de>
Thu, 11 Jun 2009 11:46:22 +0000 (11:46 +0000)
committerFabian Keil <fk@fabiankeil.de>
Thu, 11 Jun 2009 11:46:22 +0000 (11:46 +0000)
cgi.c
jcc.c
project.h
templates/connection-timeout [new file with mode: 0644]

diff --git a/cgi.c b/cgi.c
index a470c2b..31d3169 100644 (file)
--- a/cgi.c
+++ b/cgi.c
@@ -1,4 +1,4 @@
-const char cgi_rcs[] = "$Id: cgi.c,v 1.119 2009/05/28 21:13:34 fabiankeil Exp $";
+const char cgi_rcs[] = "$Id: cgi.c,v 1.120 2009/06/11 11:44:25 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/cgi.c,v $
@@ -957,6 +957,18 @@ struct http_response *error_response(struct client_state *csp,
       }
       rsp->reason = RSP_REASON_CONNECT_FAILED;
    }
+   else if (!strcmp(templatename, "connection-timeout"))
+   {
+      rsp->status = strdup("504 Connection timeout");
+      /* XXX: This check should be factored out of this block */
+      if (rsp->status == NULL)
+      {
+         free_map(exports);
+         free_http_response(rsp);
+         return cgi_error_memory();
+      }
+      rsp->reason = RSP_REASON_CONNECTION_TIMEOUT;
+   }
 
    err = template_fill_for_cgi(csp, templatename, exports, rsp);
    if (err)
diff --git a/jcc.c b/jcc.c
index 336ce62..cc37def 100644 (file)
--- a/jcc.c
+++ b/jcc.c
@@ -1,4 +1,4 @@
-const char jcc_rcs[] = "$Id: jcc.c,v 1.253 2009/06/08 16:50:35 fabiankeil Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.254 2009/06/11 11:44:25 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/jcc.c,v $
@@ -278,13 +278,12 @@ static const char TOO_MANY_CONNECTIONS_RESPONSE[] =
    "Connection: close\r\n\r\n"
    "Maximum number of open connections reached.\r\n";
 
-/* XXX: should be a template */
-static const char CONNECTION_TIMEOUT_RESPONSE[] =
+static const char CLIENT_CONNECTION_TIMEOUT_RESPONSE[] =
    "HTTP/1.0 504 Connection timeout\r\n"
    "Proxy-Agent: Privoxy " VERSION "\r\n"
    "Content-Type: text/plain\r\n"
    "Connection: close\r\n\r\n"
-   "The connection timed out.\r\n";
+   "The connection timed out because the client request didn't arrive in time.\r\n";
 
 /* A function to crunch a response */
 typedef struct http_response *(*crunch_func_ptr)(struct client_state *);
@@ -664,6 +663,9 @@ static const char *crunch_reason(const struct http_response *rsp)
       case RSP_REASON_OUT_OF_MEMORY:
          reason = "Out of memory (may mask other reasons)";
          break;
+      case RSP_REASON_CONNECTION_TIMEOUT:
+         reason = "Connection timeout";
+         break;
       default:
          reason = "No reason recorded";
          break;
@@ -1176,8 +1178,8 @@ static char *get_request_line(struct client_state *csp)
       {
          log_error(LOG_LEVEL_ERROR,
             "Stopped waiting for the request line.");
-         write_socket(csp->cfd, CONNECTION_TIMEOUT_RESPONSE,
-            strlen(CONNECTION_TIMEOUT_RESPONSE));
+         write_socket(csp->cfd, CLIENT_CONNECTION_TIMEOUT_RESPONSE,
+            strlen(CLIENT_CONNECTION_TIMEOUT_RESPONSE));
          return NULL;
       }
 
@@ -1772,8 +1774,7 @@ static void chat(struct client_state *csp)
             "Didn't receive data in time: %s", http->url);
          if ((byte_count == 0) && (http->ssl == 0))
          {
-            write_socket(csp->cfd, CONNECTION_TIMEOUT_RESPONSE,
-               strlen(CONNECTION_TIMEOUT_RESPONSE));
+            send_crunch_response(csp, error_response(csp, "connection-timeout"));
          }
          mark_server_socket_tainted(csp);
          return;
index b4a7020..7135760 100644 (file)
--- a/project.h
+++ b/project.h
@@ -1,7 +1,7 @@
 #ifndef PROJECT_H_INCLUDED
 #define PROJECT_H_INCLUDED
 /** Version string. */
-#define PROJECT_H_VERSION "$Id: project.h,v 1.139 2009/06/03 16:42:49 fabiankeil Exp $"
+#define PROJECT_H_VERSION "$Id: project.h,v 1.140 2009/06/08 16:47:07 fabiankeil Exp $"
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/project.h,v $
@@ -318,6 +318,7 @@ struct http_request
 #define RSP_REASON_CONNECT_FAILED     8
 #define RSP_REASON_OUT_OF_MEMORY      9
 #define RSP_REASON_INTERNAL_ERROR     10
+#define RSP_REASON_CONNECTION_TIMEOUT 11
 
 /**
  * Response generated by CGI, blocker, or error handler
diff --git a/templates/connection-timeout b/templates/connection-timeout
new file mode 100644 (file)
index 0000000..c65e291
--- /dev/null
@@ -0,0 +1,86 @@
+##########################################################
+#
+# connection-timeout Error Output template for Privoxy.
+#
+##########################################################
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+
+<head>
+  <title>504 - Connection timeout (Privoxy@@my-hostname@)</title>
+  <meta http-equiv="Content-Style-Type" content="text/css">
+  <meta http-equiv="Content-Script-Type" content="text/javascript">
+  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+  <meta name="robots" content="noindex,nofollow">
+  <link rel="shortcut icon" href="@default-cgi@error-favicon.ico">
+  <style type="text/css">
+#include cgi-style.css
+  </style>
+</head>
+
+<body>
+
+  <table summary="" cellpadding="20" cellspacing="10" border="0" width="100%">
+    <tr>
+      <td class="status">
+        504
+      </td>
+      <td class="title" style="width: 100%">
+
+#include mod-title
+
+      </td>
+    </tr>
+
+<!-- @if-unstable-start -->
+# This will only appear if CODE_STATUS is "alpha" or "beta". See configure.in
+    <tr>
+      <td class="warning" colspan="2">
+
+#include mod-unstable-warning
+
+      </td>
+    </tr>
+<!-- if-unstable-end@ -->
+
+    <tr>
+      <td class="warning" colspan=2>
+        <h2>Connection timeout</h2>
+          <p>Your request for <a href="@protocol@@hostport@@path@"><b>@protocol@@hostport@@path@</b></a>
+          could not be fulfilled, because the connection to <b>@host@</b> (@host-ip@) timed out.
+          </p>
+          <p>This is often a temporary failure, so you might just
+            <a href="@protocol@@hostport@@path@">try again</a>.
+         </p>
+      </td>
+    </tr>
+
+    <tr>
+      <td class="box" colspan="2">
+        <h2>More Privoxy:</h2>
+        <ul>@menu@<li><a href="@user-manual@">Documentation</a></li></ul>
+      </td>
+    </tr>
+
+    <tr>
+      <td class="info" colspan="2">
+
+#include mod-support-and-service
+
+      </td>
+    </tr>
+
+<!-- @if-have-help-info-start -->
+    <tr>
+      <td class="info" colspan="2">
+
+#include mod-local-help
+
+      </td>
+    </tr>
+<!-- if-have-help-info-end@ -->
+
+  </table>
+
+</body>
+</html>