apr_uint16_t size;
const char *tenc;
int havebody = 1;
- int isok = 1;
+ int output_failed = 0;
+ int backend_failed = 0;
apr_off_t bb_len;
int data_sent = 0;
int rv = 0;
conn_poll->desc.s = conn->sock;
bufsiz = maxsize;
- while (isok) {
+ for (;;) {
switch (result) {
case CMD_AJP13_GET_BODY_CHUNK:
if (havebody) {
ap_log_error(APLOG_MARK, APLOG_DEBUG, status,
r->server,
"ap_get_brigade failed");
- isok = 0;
+ output_failed = 1;
break;
}
bufsiz = maxsize;
ap_log_error(APLOG_MARK, APLOG_DEBUG, status,
r->server,
"apr_brigade_flatten failed");
- isok = 0;
+ output_failed = 1;
break;
}
}
if (status != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_DEBUG, status, r->server,
"ajp_send_data_msg failed");
- isok = 0;
+ backend_failed = 1;
break;
}
conn->worker->s->transferred += bufsiz;
*/
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
"ap_proxy_ajp_request error read after end");
- isok = 0;
+ backend_failed = 1;
}
break;
case CMD_AJP13_SEND_HEADERS:
/* AJP13_SEND_HEADERS: process them */
status = ajp_parse_header(r, conf, conn->data);
if (status != APR_SUCCESS) {
- isok = 0;
+ backend_failed = 1;
}
break;
case CMD_AJP13_SEND_BODY_CHUNK:
output_brigade) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"proxy: error processing body");
- isok = 0;
+ output_failed = 1;
}
data_sent = 1;
apr_brigade_cleanup(output_brigade);
}
else {
- isok = 0;
+ backend_failed = 1;
}
break;
case CMD_AJP13_END_RESPONSE:
output_brigade) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
"proxy: error processing end");
- isok = 0;
+ output_failed = 1;
}
/* XXX: what about flush here? See mod_jk */
data_sent = 1;
break;
default:
- isok = 0;
+ backend_failed = 1;
break;
}
/*
* If connection has been aborted by client: Stop working.
* Nevertheless, we regard our operation so far as a success:
- * So do not set isok to 0 and set result to CMD_AJP13_END_RESPONSE
+ * So reset output_failed to 0 and set result to CMD_AJP13_END_RESPONSE
* But: Close this connection to the backend.
*/
if (r->connection->aborted) {
conn->close++;
+ output_failed = 0;
result = CMD_AJP13_END_RESPONSE;
- break;
}
- if (!isok)
- break;
-
- if (result == CMD_AJP13_END_RESPONSE)
+ /*
+ * We either have finished successfully or we failed.
+ * So bail out
+ */
+ if ((result == CMD_AJP13_END_RESPONSE) || backend_failed
+ || output_failed)
break;
/* read the response */
status = ajp_read_header(conn->sock, r, maxsize,
(ajp_msg_t **)&(conn->data));
if (status != APR_SUCCESS) {
- isok = 0;
+ backend_failed = 1;
ap_log_error(APLOG_MARK, APLOG_DEBUG, status, r->server,
"ajp_read_header failed");
break;
*/
apr_brigade_cleanup(output_brigade);
- if (! isok) {
+ if (backend_failed || output_failed) {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+ "proxy: Processing of request failed backend: %i, "
+ "output: %i", backend_failed, output_failed);
/* We had a failure: Close connection to backend */
conn->close++;
+ /* Return DONE to avoid error messages being added to the stream */
+ if (data_sent) {
+ rv = DONE;
+ }
+ }
+ else {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+ "proxy: got response from %pI (%s)",
+ conn->worker->cp->addr,
+ conn->worker->hostname);
+ rv = OK;
+ }
+
+ if (backend_failed) {
ap_log_error(APLOG_MARK, APLOG_ERR, status, r->server,
"proxy: dialog to %pI (%s) failed",
conn->worker->cp->addr,
*/
if (data_sent) {
ap_proxy_backend_broke(r, output_brigade);
- /* Return DONE to avoid error messages being added to the stream */
- rv = DONE;
} else
rv = HTTP_SERVICE_UNAVAILABLE;
}
apr_brigade_destroy(output_brigade);
- if (rv)
- return rv;
-
- /* Nice we have answer to send to the client */
- if (result == CMD_AJP13_END_RESPONSE && isok) {
- ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
- "proxy: got response from %pI (%s)",
- conn->worker->cp->addr,
- conn->worker->hostname);
- return OK;
- }
-
- ap_log_error(APLOG_MARK, APLOG_ERR, status, r->server,
- "proxy: got bad response (%d) from %pI (%s)",
- result,
- conn->worker->cp->addr,
- conn->worker->hostname);
-
- /* We had a failure: Close connection to backend */
- conn->close++;
- return HTTP_SERVICE_UNAVAILABLE;
+ return rv;
}
/*