|
Packit |
90a5c9 |
/* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
* contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
* this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
* (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
* the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
* See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
* limitations under the License.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* AJP routines for Apache proxy */
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "mod_proxy.h"
|
|
Packit |
90a5c9 |
#include "ajp.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
module AP_MODULE_DECLARE_DATA proxy_ajp_module;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Canonicalise http-like URLs.
|
|
Packit |
90a5c9 |
* scheme is the scheme for the URL
|
|
Packit |
90a5c9 |
* url is the URL starting with the first '/'
|
|
Packit |
90a5c9 |
* def_port is the default port for this scheme.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static int proxy_ajp_canon(request_rec *r, char *url)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
char *host, *path, sport[7];
|
|
Packit |
90a5c9 |
char *search = NULL;
|
|
Packit |
90a5c9 |
const char *err;
|
|
Packit |
90a5c9 |
apr_port_t port, def_port;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* ap_port_of_scheme() */
|
|
Packit |
90a5c9 |
if (strncasecmp(url, "ajp:", 4) == 0) {
|
|
Packit |
90a5c9 |
url += 4;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
return DECLINED;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "canonicalising URL %s", url);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* do syntactic check.
|
|
Packit |
90a5c9 |
* We break the URL into host, port, path, search
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
port = def_port = ap_proxy_port_of_scheme("ajp");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
|
|
Packit |
90a5c9 |
if (err) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00867) "error parsing URL %s: %s",
|
|
Packit |
90a5c9 |
url, err);
|
|
Packit |
90a5c9 |
return HTTP_BAD_REQUEST;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* now parse path/search args, according to rfc1738:
|
|
Packit |
90a5c9 |
* process the path. With proxy-nocanon set (by
|
|
Packit |
90a5c9 |
* mod_proxy) we use the raw, unparsed uri
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (apr_table_get(r->notes, "proxy-nocanon")) {
|
|
Packit |
90a5c9 |
path = url; /* this is the raw path */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
path = ap_proxy_canonenc(r->pool, url, strlen(url), enc_path, 0,
|
|
Packit |
90a5c9 |
r->proxyreq);
|
|
Packit |
90a5c9 |
search = r->args;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (path == NULL)
|
|
Packit |
90a5c9 |
return HTTP_BAD_REQUEST;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (port != def_port)
|
|
Packit |
90a5c9 |
apr_snprintf(sport, sizeof(sport), ":%d", port);
|
|
Packit |
90a5c9 |
else
|
|
Packit |
90a5c9 |
sport[0] = '\0';
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (ap_strchr_c(host, ':')) {
|
|
Packit |
90a5c9 |
/* if literal IPv6 address */
|
|
Packit |
90a5c9 |
host = apr_pstrcat(r->pool, "[", host, "]", NULL);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
r->filename = apr_pstrcat(r->pool, "proxy:ajp://", host, sport,
|
|
Packit |
90a5c9 |
"/", path, (search) ? "?" : "",
|
|
Packit |
90a5c9 |
(search) ? search : "", NULL);
|
|
Packit |
90a5c9 |
return OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define METHOD_NON_IDEMPOTENT 0
|
|
Packit |
90a5c9 |
#define METHOD_IDEMPOTENT 1
|
|
Packit |
90a5c9 |
#define METHOD_IDEMPOTENT_WITH_ARGS 2
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static int is_idempotent(request_rec *r)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* RFC2616 (9.1.2): GET, HEAD, PUT, DELETE, OPTIONS, TRACE are considered
|
|
Packit |
90a5c9 |
* idempotent. Hint: HEAD requests use M_GET as method number as well.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
switch (r->method_number) {
|
|
Packit |
90a5c9 |
case M_GET:
|
|
Packit |
90a5c9 |
case M_DELETE:
|
|
Packit |
90a5c9 |
case M_PUT:
|
|
Packit |
90a5c9 |
case M_OPTIONS:
|
|
Packit |
90a5c9 |
case M_TRACE:
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* If the request has arguments it might have side-effects and thus
|
|
Packit |
90a5c9 |
* it might be undesirable to resend it to a backend again
|
|
Packit |
90a5c9 |
* automatically.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (r->args) {
|
|
Packit |
90a5c9 |
return METHOD_IDEMPOTENT_WITH_ARGS;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return METHOD_IDEMPOTENT;
|
|
Packit |
90a5c9 |
/* Everything else is not considered idempotent. */
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
return METHOD_NON_IDEMPOTENT;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static apr_off_t get_content_length(request_rec * r)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_off_t len = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (r->main == NULL) {
|
|
Packit |
90a5c9 |
const char *clp = apr_table_get(r->headers_in, "Content-Length");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (clp) {
|
|
Packit |
90a5c9 |
char *errp;
|
|
Packit |
90a5c9 |
if (apr_strtoff(&len, clp, &errp, 10) || *errp || len < 0) {
|
|
Packit |
90a5c9 |
len = 0; /* parse error */
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return len;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* XXX: AJP Auto Flushing
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* When processing CMD_AJP13_SEND_BODY_CHUNK AJP messages we will do a poll
|
|
Packit |
90a5c9 |
* with FLUSH_WAIT milliseconds timeout to determine if more data is currently
|
|
Packit |
90a5c9 |
* available at the backend. If there is no more data available, we flush
|
|
Packit |
90a5c9 |
* the data to the client by adding a flush bucket to the brigade we pass
|
|
Packit |
90a5c9 |
* up the filter chain.
|
|
Packit |
90a5c9 |
* This is only a bandaid to fix the AJP/1.3 protocol shortcoming of not
|
|
Packit |
90a5c9 |
* sending (actually not having defined) a flush message, when the data
|
|
Packit |
90a5c9 |
* should be flushed to the client. As soon as this protocol shortcoming is
|
|
Packit |
90a5c9 |
* fixed this code should be removed.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* For further discussion see PR37100.
|
|
Packit |
90a5c9 |
* http://issues.apache.org/bugzilla/show_bug.cgi?id=37100
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* process the request and write the response.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static int ap_proxy_ajp_request(apr_pool_t *p, request_rec *r,
|
|
Packit |
90a5c9 |
proxy_conn_rec *conn,
|
|
Packit |
90a5c9 |
conn_rec *origin,
|
|
Packit |
90a5c9 |
proxy_dir_conf *conf,
|
|
Packit |
90a5c9 |
apr_uri_t *uri,
|
|
Packit |
90a5c9 |
char *url, char *server_portstr)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_status_t status;
|
|
Packit |
90a5c9 |
int result;
|
|
Packit |
90a5c9 |
apr_bucket *e;
|
|
Packit |
90a5c9 |
apr_bucket_brigade *input_brigade;
|
|
Packit |
90a5c9 |
apr_bucket_brigade *output_brigade;
|
|
Packit |
90a5c9 |
ajp_msg_t *msg;
|
|
Packit |
90a5c9 |
apr_size_t bufsiz = 0;
|
|
Packit |
90a5c9 |
char *buff;
|
|
Packit |
90a5c9 |
char *send_body_chunk_buff;
|
|
Packit |
90a5c9 |
apr_uint16_t size;
|
|
Packit |
90a5c9 |
apr_byte_t conn_reuse = 0;
|
|
Packit |
90a5c9 |
const char *tenc;
|
|
Packit |
90a5c9 |
int havebody = 1;
|
|
Packit |
90a5c9 |
int client_failed = 0;
|
|
Packit |
90a5c9 |
int backend_failed = 0;
|
|
Packit |
90a5c9 |
apr_off_t bb_len;
|
|
Packit |
90a5c9 |
int data_sent = 0;
|
|
Packit |
90a5c9 |
int request_ended = 0;
|
|
Packit |
90a5c9 |
int headers_sent = 0;
|
|
Packit |
90a5c9 |
int rv = OK;
|
|
Packit |
90a5c9 |
apr_int32_t conn_poll_fd;
|
|
Packit |
90a5c9 |
apr_pollfd_t *conn_poll;
|
|
Packit |
90a5c9 |
proxy_server_conf *psf =
|
|
Packit |
90a5c9 |
ap_get_module_config(r->server->module_config, &proxy_module);
|
|
Packit |
90a5c9 |
apr_size_t maxsize = AJP_MSG_BUFFER_SZ;
|
|
Packit |
90a5c9 |
int send_body = 0;
|
|
Packit |
90a5c9 |
apr_off_t content_length = 0;
|
|
Packit |
90a5c9 |
int original_status = r->status;
|
|
Packit |
90a5c9 |
const char *original_status_line = r->status_line;
|
|
Packit |
0d3a01 |
const char *secret = NULL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (psf->io_buffer_size_set)
|
|
Packit |
90a5c9 |
maxsize = psf->io_buffer_size;
|
|
Packit |
90a5c9 |
if (maxsize > AJP_MAX_BUFFER_SZ)
|
|
Packit |
90a5c9 |
maxsize = AJP_MAX_BUFFER_SZ;
|
|
Packit |
90a5c9 |
else if (maxsize < AJP_MSG_BUFFER_SZ)
|
|
Packit |
90a5c9 |
maxsize = AJP_MSG_BUFFER_SZ;
|
|
Packit |
90a5c9 |
maxsize = APR_ALIGN(maxsize, 1024);
|
|
Packit |
90a5c9 |
|
|
Packit |
0d3a01 |
if (*conn->worker->s->secret)
|
|
Packit |
0d3a01 |
secret = conn->worker->s->secret;
|
|
Packit |
0d3a01 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Send the AJP request to the remote server
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* send request headers */
|
|
Packit |
0d3a01 |
status = ajp_send_header(conn->sock, r, maxsize, uri, secret);
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
conn->close = 1;
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00868)
|
|
Packit |
90a5c9 |
"request failed to %pI (%s)",
|
|
Packit |
90a5c9 |
conn->worker->cp->addr,
|
|
Packit |
90a5c9 |
conn->worker->s->hostname_ex);
|
|
Packit |
90a5c9 |
if (status == AJP_EOVERFLOW)
|
|
Packit |
90a5c9 |
return HTTP_BAD_REQUEST;
|
|
Packit |
90a5c9 |
else if (status == AJP_EBAD_METHOD) {
|
|
Packit |
90a5c9 |
return HTTP_NOT_IMPLEMENTED;
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* This is only non fatal when the method is idempotent. In this
|
|
Packit |
90a5c9 |
* case we can dare to retry it with a different worker if we are
|
|
Packit |
90a5c9 |
* a balancer member.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (is_idempotent(r) == METHOD_IDEMPOTENT) {
|
|
Packit |
90a5c9 |
return HTTP_SERVICE_UNAVAILABLE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return HTTP_INTERNAL_SERVER_ERROR;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* allocate an AJP message to store the data of the buckets */
|
|
Packit |
90a5c9 |
bufsiz = maxsize;
|
|
Packit |
90a5c9 |
status = ajp_alloc_data_msg(r->pool, &buff, &bufsiz, &msg;;
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
/* We had a failure: Close connection to backend */
|
|
Packit |
90a5c9 |
conn->close = 1;
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00869)
|
|
Packit |
90a5c9 |
"ajp_alloc_data_msg failed");
|
|
Packit |
90a5c9 |
return HTTP_INTERNAL_SERVER_ERROR;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* read the first bloc of data */
|
|
Packit |
90a5c9 |
input_brigade = apr_brigade_create(p, r->connection->bucket_alloc);
|
|
Packit |
90a5c9 |
tenc = apr_table_get(r->headers_in, "Transfer-Encoding");
|
|
Packit |
90a5c9 |
if (tenc && (strcasecmp(tenc, "chunked") == 0)) {
|
|
Packit |
90a5c9 |
/* The AJP protocol does not want body data yet */
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00870) "request is chunked");
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
/* Get client provided Content-Length header */
|
|
Packit |
90a5c9 |
content_length = get_content_length(r);
|
|
Packit |
90a5c9 |
status = ap_get_brigade(r->input_filters, input_brigade,
|
|
Packit |
90a5c9 |
AP_MODE_READBYTES, APR_BLOCK_READ,
|
|
Packit |
90a5c9 |
maxsize - AJP_HEADER_SZ);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
/* We had a failure: Close connection to backend */
|
|
Packit |
90a5c9 |
conn->close = 1;
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00871)
|
|
Packit |
90a5c9 |
"ap_get_brigade failed");
|
|
Packit |
90a5c9 |
apr_brigade_destroy(input_brigade);
|
|
Packit |
90a5c9 |
return ap_map_http_request_error(status, HTTP_BAD_REQUEST);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* have something */
|
|
Packit |
90a5c9 |
if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(input_brigade))) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00872) "APR_BUCKET_IS_EOS");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Try to send something */
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00873)
|
|
Packit |
90a5c9 |
"data to read (max %" APR_SIZE_T_FMT
|
|
Packit |
90a5c9 |
" at %" APR_SIZE_T_FMT ")", bufsiz, msg->pos);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
status = apr_brigade_flatten(input_brigade, buff, &bufsiz);
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
/* We had a failure: Close connection to backend */
|
|
Packit |
90a5c9 |
conn->close = 1;
|
|
Packit |
90a5c9 |
apr_brigade_destroy(input_brigade);
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00874)
|
|
Packit |
90a5c9 |
"apr_brigade_flatten");
|
|
Packit |
90a5c9 |
return HTTP_INTERNAL_SERVER_ERROR;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
apr_brigade_cleanup(input_brigade);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00875)
|
|
Packit |
90a5c9 |
"got %" APR_SIZE_T_FMT " bytes of data", bufsiz);
|
|
Packit |
90a5c9 |
if (bufsiz > 0) {
|
|
Packit |
90a5c9 |
status = ajp_send_data_msg(conn->sock, msg, bufsiz);
|
|
Packit |
90a5c9 |
ajp_msg_log(r, msg, "First ajp_send_data_msg: ajp_ilink_send packet dump");
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
/* We had a failure: Close connection to backend */
|
|
Packit |
90a5c9 |
conn->close = 1;
|
|
Packit |
90a5c9 |
apr_brigade_destroy(input_brigade);
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00876)
|
|
Packit |
90a5c9 |
"send failed to %pI (%s)",
|
|
Packit |
90a5c9 |
conn->worker->cp->addr,
|
|
Packit |
90a5c9 |
conn->worker->s->hostname_ex);
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* It is fatal when we failed to send a (part) of the request
|
|
Packit |
90a5c9 |
* body.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
return HTTP_INTERNAL_SERVER_ERROR;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
conn->worker->s->transferred += bufsiz;
|
|
Packit |
90a5c9 |
send_body = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (content_length > 0) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00877)
|
|
Packit |
90a5c9 |
"read zero bytes, expecting"
|
|
Packit |
90a5c9 |
" %" APR_OFF_T_FMT " bytes",
|
|
Packit |
90a5c9 |
content_length);
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* We can only get here if the client closed the connection
|
|
Packit |
90a5c9 |
* to us without sending the body.
|
|
Packit |
90a5c9 |
* Now the connection is in the wrong state on the backend.
|
|
Packit |
90a5c9 |
* Sending an empty data msg doesn't help either as it does
|
|
Packit |
90a5c9 |
* not move this connection to the correct state on the backend
|
|
Packit |
90a5c9 |
* for later resusage by the next request again.
|
|
Packit |
90a5c9 |
* Close it to clean things up.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
conn->close = 1;
|
|
Packit |
90a5c9 |
apr_brigade_destroy(input_brigade);
|
|
Packit |
90a5c9 |
return HTTP_BAD_REQUEST;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* read the response */
|
|
Packit |
90a5c9 |
conn->data = NULL;
|
|
Packit |
90a5c9 |
status = ajp_read_header(conn->sock, r, maxsize,
|
|
Packit |
90a5c9 |
(ajp_msg_t **)&(conn->data));
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
/* We had a failure: Close connection to backend */
|
|
Packit |
90a5c9 |
conn->close = 1;
|
|
Packit |
90a5c9 |
apr_brigade_destroy(input_brigade);
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00878)
|
|
Packit |
90a5c9 |
"read response failed from %pI (%s)",
|
|
Packit |
90a5c9 |
conn->worker->cp->addr,
|
|
Packit |
90a5c9 |
conn->worker->s->hostname_ex);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* If we had a successful cping/cpong and then a timeout
|
|
Packit |
90a5c9 |
* we assume it is a request that cause a back-end timeout,
|
|
Packit |
90a5c9 |
* but doesn't affect the whole worker.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (APR_STATUS_IS_TIMEUP(status) && conn->worker->s->ping_timeout_set) {
|
|
Packit |
90a5c9 |
return HTTP_GATEWAY_TIME_OUT;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* This is only non fatal when we have not sent (parts) of a possible
|
|
Packit |
90a5c9 |
* request body so far (we do not store it and thus cannot send it
|
|
Packit |
90a5c9 |
* again) and the method is idempotent. In this case we can dare to
|
|
Packit |
90a5c9 |
* retry it with a different worker if we are a balancer member.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (!send_body && (is_idempotent(r) == METHOD_IDEMPOTENT)) {
|
|
Packit |
90a5c9 |
return HTTP_SERVICE_UNAVAILABLE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return HTTP_INTERNAL_SERVER_ERROR;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* parse the response */
|
|
Packit |
90a5c9 |
result = ajp_parse_type(r, conn->data);
|
|
Packit |
90a5c9 |
output_brigade = apr_brigade_create(p, r->connection->bucket_alloc);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Prepare apr_pollfd_t struct for possible later check if there is currently
|
|
Packit |
90a5c9 |
* data available from the backend (do not flush response to client)
|
|
Packit |
90a5c9 |
* or not (flush response to client)
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
conn_poll = apr_pcalloc(p, sizeof(apr_pollfd_t));
|
|
Packit |
90a5c9 |
conn_poll->reqevents = APR_POLLIN;
|
|
Packit |
90a5c9 |
conn_poll->desc_type = APR_POLL_SOCKET;
|
|
Packit |
90a5c9 |
conn_poll->desc.s = conn->sock;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
bufsiz = maxsize;
|
|
Packit |
90a5c9 |
for (;;) {
|
|
Packit |
90a5c9 |
switch (result) {
|
|
Packit |
90a5c9 |
case CMD_AJP13_GET_BODY_CHUNK:
|
|
Packit |
90a5c9 |
if (havebody) {
|
|
Packit |
90a5c9 |
if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(input_brigade))) {
|
|
Packit |
90a5c9 |
/* This is the end */
|
|
Packit |
90a5c9 |
bufsiz = 0;
|
|
Packit |
90a5c9 |
havebody = 0;
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00879)
|
|
Packit |
90a5c9 |
"APR_BUCKET_IS_EOS");
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
status = ap_get_brigade(r->input_filters, input_brigade,
|
|
Packit |
90a5c9 |
AP_MODE_READBYTES,
|
|
Packit |
90a5c9 |
APR_BLOCK_READ,
|
|
Packit |
90a5c9 |
maxsize - AJP_HEADER_SZ);
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00880)
|
|
Packit |
90a5c9 |
"ap_get_brigade failed");
|
|
Packit |
90a5c9 |
if (APR_STATUS_IS_TIMEUP(status)) {
|
|
Packit |
90a5c9 |
rv = HTTP_REQUEST_TIME_OUT;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (status == AP_FILTER_ERROR) {
|
|
Packit |
90a5c9 |
rv = AP_FILTER_ERROR;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
client_failed = 1;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
bufsiz = maxsize;
|
|
Packit |
90a5c9 |
status = apr_brigade_flatten(input_brigade, buff,
|
|
Packit |
90a5c9 |
&bufsiz);
|
|
Packit |
90a5c9 |
apr_brigade_cleanup(input_brigade);
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00881)
|
|
Packit |
90a5c9 |
"apr_brigade_flatten failed");
|
|
Packit |
90a5c9 |
rv = HTTP_INTERNAL_SERVER_ERROR;
|
|
Packit |
90a5c9 |
client_failed = 1;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
ajp_msg_reset(msg);
|
|
Packit |
90a5c9 |
/* will go in ajp_send_data_msg */
|
|
Packit |
90a5c9 |
status = ajp_send_data_msg(conn->sock, msg, bufsiz);
|
|
Packit |
90a5c9 |
ajp_msg_log(r, msg, "ajp_send_data_msg after CMD_AJP13_GET_BODY_CHUNK: ajp_ilink_send packet dump");
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00882)
|
|
Packit |
90a5c9 |
"ajp_send_data_msg failed");
|
|
Packit |
90a5c9 |
backend_failed = 1;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
conn->worker->s->transferred += bufsiz;
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* something is wrong TC asks for more body but we are
|
|
Packit |
90a5c9 |
* already at the end of the body data
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00883)
|
|
Packit |
90a5c9 |
"ap_proxy_ajp_request error read after end");
|
|
Packit |
90a5c9 |
backend_failed = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case CMD_AJP13_SEND_HEADERS:
|
|
Packit |
90a5c9 |
if (headers_sent) {
|
|
Packit |
90a5c9 |
/* Do not send anything to the client.
|
|
Packit |
90a5c9 |
* Backend already send us the headers.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
backend_failed = 1;
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00884)
|
|
Packit |
90a5c9 |
"Backend sent headers twice.");
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* AJP13_SEND_HEADERS: process them */
|
|
Packit |
90a5c9 |
status = ajp_parse_header(r, conf, conn->data);
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
backend_failed = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if ((r->status == 401) && conf->error_override) {
|
|
Packit |
90a5c9 |
const char *buf;
|
|
Packit |
90a5c9 |
const char *wa = "WWW-Authenticate";
|
|
Packit |
90a5c9 |
if ((buf = apr_table_get(r->headers_out, wa))) {
|
|
Packit |
90a5c9 |
apr_table_set(r->err_headers_out, wa, buf);
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00885)
|
|
Packit |
90a5c9 |
"ap_proxy_ajp_request: origin server "
|
|
Packit |
90a5c9 |
"sent 401 without WWW-Authenticate header");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
headers_sent = 1;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case CMD_AJP13_SEND_BODY_CHUNK:
|
|
Packit |
90a5c9 |
/* AJP13_SEND_BODY_CHUNK: piece of data */
|
|
Packit |
90a5c9 |
status = ajp_parse_data(r, conn->data, &size, &send_body_chunk_buff);
|
|
Packit |
90a5c9 |
if (status == APR_SUCCESS) {
|
|
Packit |
90a5c9 |
/* If we are overriding the errors, we can't put the content
|
|
Packit |
90a5c9 |
* of the page into the brigade.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (!conf->error_override || !ap_is_HTTP_ERROR(r->status)) {
|
|
Packit |
90a5c9 |
/* AJP13_SEND_BODY_CHUNK with zero length
|
|
Packit |
90a5c9 |
* is explicit flush message
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (size == 0) {
|
|
Packit |
90a5c9 |
if (headers_sent) {
|
|
Packit |
90a5c9 |
e = apr_bucket_flush_create(r->connection->bucket_alloc);
|
|
Packit |
90a5c9 |
APR_BRIGADE_INSERT_TAIL(output_brigade, e);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00886)
|
|
Packit |
90a5c9 |
"Ignoring flush message "
|
|
Packit |
90a5c9 |
"received before headers");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
apr_status_t rv;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Handle the case where the error document is itself reverse
|
|
Packit |
90a5c9 |
* proxied and was successful. We must maintain any previous
|
|
Packit |
90a5c9 |
* error status so that an underlying error (eg HTTP_NOT_FOUND)
|
|
Packit |
90a5c9 |
* doesn't become an HTTP_OK.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (conf->error_override && !ap_is_HTTP_ERROR(r->status)
|
|
Packit |
90a5c9 |
&& ap_is_HTTP_ERROR(original_status)) {
|
|
Packit |
90a5c9 |
r->status = original_status;
|
|
Packit |
90a5c9 |
r->status_line = original_status_line;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
e = apr_bucket_transient_create(send_body_chunk_buff, size,
|
|
Packit |
90a5c9 |
r->connection->bucket_alloc);
|
|
Packit |
90a5c9 |
APR_BRIGADE_INSERT_TAIL(output_brigade, e);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((conn->worker->s->flush_packets == flush_on) ||
|
|
Packit |
90a5c9 |
((conn->worker->s->flush_packets == flush_auto) &&
|
|
Packit |
90a5c9 |
((rv = apr_poll(conn_poll, 1, &conn_poll_fd,
|
|
Packit |
90a5c9 |
conn->worker->s->flush_wait))
|
|
Packit |
90a5c9 |
!= APR_SUCCESS) &&
|
|
Packit |
90a5c9 |
APR_STATUS_IS_TIMEUP(rv))) {
|
|
Packit |
90a5c9 |
e = apr_bucket_flush_create(r->connection->bucket_alloc);
|
|
Packit |
90a5c9 |
APR_BRIGADE_INSERT_TAIL(output_brigade, e);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
apr_brigade_length(output_brigade, 0, &bb_len);
|
|
Packit |
90a5c9 |
if (bb_len != -1)
|
|
Packit |
90a5c9 |
conn->worker->s->read += bb_len;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (headers_sent) {
|
|
Packit |
90a5c9 |
if (ap_pass_brigade(r->output_filters,
|
|
Packit |
90a5c9 |
output_brigade) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00887)
|
|
Packit |
90a5c9 |
"error processing body.%s",
|
|
Packit |
90a5c9 |
r->connection->aborted ?
|
|
Packit |
90a5c9 |
" Client aborted connection." : "");
|
|
Packit |
90a5c9 |
client_failed = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
data_sent = 1;
|
|
Packit |
90a5c9 |
apr_brigade_cleanup(output_brigade);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
backend_failed = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case CMD_AJP13_END_RESPONSE:
|
|
Packit |
90a5c9 |
/* If we are overriding the errors, we must not send anything to
|
|
Packit |
90a5c9 |
* the client, especially as the brigade already contains headers.
|
|
Packit |
90a5c9 |
* So do nothing here, and it will be cleaned up below.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
status = ajp_parse_reuse(r, conn->data, &conn_reuse);
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
backend_failed = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (!conf->error_override || !ap_is_HTTP_ERROR(r->status)) {
|
|
Packit |
90a5c9 |
e = apr_bucket_eos_create(r->connection->bucket_alloc);
|
|
Packit |
90a5c9 |
APR_BRIGADE_INSERT_TAIL(output_brigade, e);
|
|
Packit |
90a5c9 |
if (ap_pass_brigade(r->output_filters,
|
|
Packit |
90a5c9 |
output_brigade) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00888)
|
|
Packit |
90a5c9 |
"error processing end");
|
|
Packit |
90a5c9 |
client_failed = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* XXX: what about flush here? See mod_jk */
|
|
Packit |
90a5c9 |
data_sent = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
request_ended = 1;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
backend_failed = 1;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* If connection has been aborted by client: Stop working.
|
|
Packit |
90a5c9 |
* Pretend we are done (data_sent) to avoid further processing.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (r->connection->aborted) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02821)
|
|
Packit |
90a5c9 |
"client connection aborted");
|
|
Packit |
90a5c9 |
/* no response yet (or ever), set status for access log */
|
|
Packit |
90a5c9 |
if (!headers_sent) {
|
|
Packit |
90a5c9 |
r->status = HTTP_BAD_REQUEST;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
client_failed = 1;
|
|
Packit |
90a5c9 |
/* return DONE */
|
|
Packit |
90a5c9 |
data_sent = 1;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* We either have finished successfully or we failed.
|
|
Packit |
90a5c9 |
* So bail out
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if ((result == CMD_AJP13_END_RESPONSE)
|
|
Packit |
90a5c9 |
|| backend_failed || client_failed)
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* read the response */
|
|
Packit |
90a5c9 |
status = ajp_read_header(conn->sock, r, maxsize,
|
|
Packit |
90a5c9 |
(ajp_msg_t **)&(conn->data));
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
backend_failed = 1;
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00889)
|
|
Packit |
90a5c9 |
"ajp_read_header failed");
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
result = ajp_parse_type(r, conn->data);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
apr_brigade_destroy(input_brigade);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Clear output_brigade to remove possible buckets that remained there
|
|
Packit |
90a5c9 |
* after an error.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_brigade_cleanup(output_brigade);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (backend_failed || client_failed) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00890)
|
|
Packit |
90a5c9 |
"Processing of request failed backend: %i, client: %i",
|
|
Packit |
90a5c9 |
backend_failed, client_failed);
|
|
Packit |
90a5c9 |
/* We had a failure: Close connection to backend */
|
|
Packit |
90a5c9 |
conn->close = 1;
|
|
Packit |
90a5c9 |
if (data_sent) {
|
|
Packit |
90a5c9 |
/* Return DONE to avoid error messages being added to the stream */
|
|
Packit |
90a5c9 |
rv = DONE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!request_ended) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00891)
|
|
Packit |
90a5c9 |
"Processing of request didn't terminate cleanly");
|
|
Packit |
90a5c9 |
/* We had a failure: Close connection to backend */
|
|
Packit |
90a5c9 |
conn->close = 1;
|
|
Packit |
90a5c9 |
backend_failed = 1;
|
|
Packit |
90a5c9 |
if (data_sent) {
|
|
Packit |
90a5c9 |
/* Return DONE to avoid error messages being added to the stream */
|
|
Packit |
90a5c9 |
rv = DONE;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (!conn_reuse) {
|
|
Packit |
90a5c9 |
/* Our backend signalled connection close */
|
|
Packit |
90a5c9 |
conn->close = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00892)
|
|
Packit |
90a5c9 |
"got response from %pI (%s)",
|
|
Packit |
90a5c9 |
conn->worker->cp->addr,
|
|
Packit |
90a5c9 |
conn->worker->s->hostname_ex);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (conf->error_override && ap_is_HTTP_ERROR(r->status)) {
|
|
Packit |
90a5c9 |
/* clear r->status for override error, otherwise ErrorDocument
|
|
Packit |
90a5c9 |
* thinks that this is a recursive error, and doesn't find the
|
|
Packit |
90a5c9 |
* custom error page
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
rv = r->status;
|
|
Packit |
90a5c9 |
r->status = HTTP_OK;
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* prevent proxy_handler() from treating this as an
|
|
Packit |
90a5c9 |
* internal error.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
apr_table_setn(r->notes, "proxy-error-override", "1");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
rv = OK;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (backend_failed) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00893)
|
|
Packit |
90a5c9 |
"dialog to %pI (%s) failed",
|
|
Packit |
90a5c9 |
conn->worker->cp->addr,
|
|
Packit |
90a5c9 |
conn->worker->s->hostname_ex);
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* If we already send data, signal a broken backend connection
|
|
Packit |
90a5c9 |
* upwards in the chain.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (data_sent) {
|
|
Packit |
90a5c9 |
ap_proxy_backend_broke(r, output_brigade);
|
|
Packit |
90a5c9 |
} else if (!send_body && (is_idempotent(r) == METHOD_IDEMPOTENT)) {
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* This is only non fatal when we have not send (parts) of a possible
|
|
Packit |
90a5c9 |
* request body so far (we do not store it and thus cannot send it
|
|
Packit |
90a5c9 |
* again) and the method is idempotent. In this case we can dare to
|
|
Packit |
90a5c9 |
* retry it with a different worker if we are a balancer member.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
rv = HTTP_SERVICE_UNAVAILABLE;
|
|
Packit |
90a5c9 |
} else {
|
|
Packit |
90a5c9 |
rv = HTTP_INTERNAL_SERVER_ERROR;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (client_failed) {
|
|
Packit |
90a5c9 |
int level = (r->connection->aborted) ? APLOG_DEBUG : APLOG_ERR;
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, level, status, r, APLOGNO(02822)
|
|
Packit |
90a5c9 |
"dialog with client %pI failed",
|
|
Packit |
90a5c9 |
r->connection->client_addr);
|
|
Packit |
90a5c9 |
if (rv == OK) {
|
|
Packit |
90a5c9 |
rv = HTTP_BAD_REQUEST;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Ensure that we sent an EOS bucket thru the filter chain, if we already
|
|
Packit |
90a5c9 |
* have sent some data. Maybe ap_proxy_backend_broke was called and added
|
|
Packit |
90a5c9 |
* one to the brigade already (no longer making it empty). So we should
|
|
Packit |
90a5c9 |
* not do this in this case.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (data_sent && !r->eos_sent && !r->connection->aborted
|
|
Packit |
90a5c9 |
&& APR_BRIGADE_EMPTY(output_brigade)) {
|
|
Packit |
90a5c9 |
e = apr_bucket_eos_create(r->connection->bucket_alloc);
|
|
Packit |
90a5c9 |
APR_BRIGADE_INSERT_TAIL(output_brigade, e);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* If we have added something to the brigade above, send it */
|
|
Packit |
90a5c9 |
if (!APR_BRIGADE_EMPTY(output_brigade)
|
|
Packit |
90a5c9 |
&& ap_pass_brigade(r->output_filters, output_brigade) != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
rv = AP_FILTER_ERROR;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
apr_brigade_destroy(output_brigade);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (apr_table_get(r->subprocess_env, "proxy-nokeepalive")) {
|
|
Packit |
90a5c9 |
conn->close = 1;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
return rv;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* This handles ajp:// URLs
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
static int proxy_ajp_handler(request_rec *r, proxy_worker *worker,
|
|
Packit |
90a5c9 |
proxy_server_conf *conf,
|
|
Packit |
90a5c9 |
char *url, const char *proxyname,
|
|
Packit |
90a5c9 |
apr_port_t proxyport)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
int status;
|
|
Packit |
90a5c9 |
char server_portstr[32];
|
|
Packit |
90a5c9 |
conn_rec *origin = NULL;
|
|
Packit |
90a5c9 |
proxy_conn_rec *backend = NULL;
|
|
Packit |
90a5c9 |
const char *scheme = "AJP";
|
|
Packit |
90a5c9 |
int retry;
|
|
Packit |
90a5c9 |
proxy_dir_conf *dconf = ap_get_module_config(r->per_dir_config,
|
|
Packit |
90a5c9 |
&proxy_module);
|
|
Packit |
90a5c9 |
apr_pool_t *p = r->pool;
|
|
Packit |
90a5c9 |
apr_uri_t *uri;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (strncasecmp(url, "ajp:", 4) != 0) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00894) "declining URL %s", url);
|
|
Packit |
90a5c9 |
return DECLINED;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
uri = apr_palloc(p, sizeof(*uri));
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00895) "serving URL %s", url);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* create space for state information */
|
|
Packit |
90a5c9 |
status = ap_proxy_acquire_connection(scheme, &backend, worker,
|
|
Packit |
90a5c9 |
r->server);
|
|
Packit |
90a5c9 |
if (status != OK) {
|
|
Packit |
90a5c9 |
if (backend) {
|
|
Packit |
90a5c9 |
backend->close = 1;
|
|
Packit |
90a5c9 |
ap_proxy_release_connection(scheme, backend, r->server);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
backend->is_ssl = 0;
|
|
Packit |
90a5c9 |
backend->close = 0;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
retry = 0;
|
|
Packit |
90a5c9 |
while (retry < 2) {
|
|
Packit |
90a5c9 |
char *locurl = url;
|
|
Packit |
90a5c9 |
/* Step One: Determine Who To Connect To */
|
|
Packit |
90a5c9 |
status = ap_proxy_determine_connection(p, r, conf, worker, backend,
|
|
Packit |
90a5c9 |
uri, &locurl, proxyname, proxyport,
|
|
Packit |
90a5c9 |
server_portstr,
|
|
Packit |
90a5c9 |
sizeof(server_portstr));
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (status != OK)
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Step Two: Make the Connection */
|
|
Packit |
90a5c9 |
if (ap_proxy_check_connection(scheme, backend, r->server, 0,
|
|
Packit |
90a5c9 |
PROXY_CHECK_CONN_EMPTY)
|
|
Packit |
90a5c9 |
&& ap_proxy_connect_backend(scheme, backend, worker,
|
|
Packit |
90a5c9 |
r->server)) {
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00896)
|
|
Packit |
90a5c9 |
"failed to make connection to backend: %s",
|
|
Packit |
90a5c9 |
backend->hostname);
|
|
Packit |
90a5c9 |
status = HTTP_SERVICE_UNAVAILABLE;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Handle CPING/CPONG */
|
|
Packit |
90a5c9 |
if (worker->s->ping_timeout_set) {
|
|
Packit |
90a5c9 |
status = ajp_handle_cping_cpong(backend->sock, r,
|
|
Packit |
90a5c9 |
worker->s->ping_timeout);
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* In case the CPING / CPONG failed for the first time we might be
|
|
Packit |
90a5c9 |
* just out of luck and got a faulty backend connection, but the
|
|
Packit |
90a5c9 |
* backend might be healthy nevertheless. So ensure that the backend
|
|
Packit |
90a5c9 |
* TCP connection gets closed and try it once again.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
if (status != APR_SUCCESS) {
|
|
Packit |
90a5c9 |
backend->close = 1;
|
|
Packit |
90a5c9 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00897)
|
|
Packit |
90a5c9 |
"cping/cpong failed to %pI (%s)",
|
|
Packit |
90a5c9 |
worker->cp->addr, worker->s->hostname_ex);
|
|
Packit |
90a5c9 |
status = HTTP_SERVICE_UNAVAILABLE;
|
|
Packit |
90a5c9 |
retry++;
|
|
Packit |
90a5c9 |
continue;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
/* Step Three: Process the Request */
|
|
Packit |
90a5c9 |
status = ap_proxy_ajp_request(p, r, backend, origin, dconf, uri, locurl,
|
|
Packit |
90a5c9 |
server_portstr);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* Do not close the socket */
|
|
Packit |
90a5c9 |
ap_proxy_release_connection(scheme, backend, r->server);
|
|
Packit |
90a5c9 |
return status;
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
static void ap_proxy_http_register_hook(apr_pool_t *p)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
proxy_hook_scheme_handler(proxy_ajp_handler, NULL, NULL, APR_HOOK_FIRST);
|
|
Packit |
90a5c9 |
proxy_hook_canon_handler(proxy_ajp_canon, NULL, NULL, APR_HOOK_FIRST);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
AP_DECLARE_MODULE(proxy_ajp) = {
|
|
Packit |
90a5c9 |
STANDARD20_MODULE_STUFF,
|
|
Packit |
90a5c9 |
NULL, /* create per-directory config structure */
|
|
Packit |
90a5c9 |
NULL, /* merge per-directory config structures */
|
|
Packit |
90a5c9 |
NULL, /* create per-server config structure */
|
|
Packit |
90a5c9 |
NULL, /* merge per-server config structures */
|
|
Packit |
90a5c9 |
NULL, /* command apr_table_t */
|
|
Packit |
90a5c9 |
ap_proxy_http_register_hook /* register hooks */
|
|
Packit |
90a5c9 |
};
|
|
Packit |
90a5c9 |
|