1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 /* AJP routines for Apache proxy */
19 #include "mod_proxy.h"
22 module AP_MODULE_DECLARE_DATA proxy_ajp_module;
25 * Canonicalise http-like URLs.
26 * scheme is the scheme for the URL
27 * url is the URL starting with the first '/'
28 * def_port is the default port for this scheme.
30 static int proxy_ajp_canon(request_rec *r, char *url)
32 char *host, *path, sport[7];
35 apr_port_t port, def_port;
37 /* ap_port_of_scheme() */
38 if (ap_casecmpstrn(url, "ajp:", 4) == 0) {
45 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "canonicalising URL %s", url);
49 * We break the URL into host, port, path, search
51 port = def_port = ap_proxy_port_of_scheme("ajp");
53 err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port);
55 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00867) "error parsing URL %s: %s",
57 return HTTP_BAD_REQUEST;
61 * now parse path/search args, according to rfc1738:
62 * process the path. With proxy-nocanon set (by
63 * mod_proxy) we use the raw, unparsed uri
65 if (apr_table_get(r->notes, "proxy-nocanon")) {
66 path = url; /* this is the raw path */
69 path = ap_proxy_canonenc(r->pool, url, strlen(url), enc_path, 0,
74 return HTTP_BAD_REQUEST;
77 apr_snprintf(sport, sizeof(sport), ":%d", port);
81 if (ap_strchr_c(host, ':')) {
82 /* if literal IPv6 address */
83 host = apr_pstrcat(r->pool, "[", host, "]", NULL);
85 r->filename = apr_pstrcat(r->pool, "proxy:ajp://", host, sport,
86 "/", path, (search) ? "?" : "",
87 (search) ? search : "", NULL);
91 #define METHOD_NON_IDEMPOTENT 0
92 #define METHOD_IDEMPOTENT 1
93 #define METHOD_IDEMPOTENT_WITH_ARGS 2
95 static int is_idempotent(request_rec *r)
98 * RFC2616 (9.1.2): GET, HEAD, PUT, DELETE, OPTIONS, TRACE are considered
99 * idempotent. Hint: HEAD requests use M_GET as method number as well.
101 switch (r->method_number) {
108 * If the request has arguments it might have side-effects and thus
109 * it might be undesirable to resend it to a backend again
113 return METHOD_IDEMPOTENT_WITH_ARGS;
115 return METHOD_IDEMPOTENT;
116 /* Everything else is not considered idempotent. */
118 return METHOD_NON_IDEMPOTENT;
122 static apr_off_t get_content_length(request_rec * r)
126 if (r->main == NULL) {
127 const char *clp = apr_table_get(r->headers_in, "Content-Length");
131 if (apr_strtoff(&len, clp, &errp, 10) || *errp || len < 0) {
132 len = 0; /* parse error */
141 * XXX: AJP Auto Flushing
143 * When processing CMD_AJP13_SEND_BODY_CHUNK AJP messages we will do a poll
144 * with FLUSH_WAIT miliseconds timeout to determine if more data is currently
145 * available at the backend. If there is no more data available, we flush
146 * the data to the client by adding a flush bucket to the brigade we pass
147 * up the filter chain.
148 * This is only a bandaid to fix the AJP/1.3 protocol shortcoming of not
149 * sending (actually not having defined) a flush message, when the data
150 * should be flushed to the client. As soon as this protocol shortcoming is
151 * fixed this code should be removed.
153 * For further discussion see PR37100.
154 * http://issues.apache.org/bugzilla/show_bug.cgi?id=37100
158 * process the request and write the response.
160 static int ap_proxy_ajp_request(apr_pool_t *p, request_rec *r,
161 proxy_conn_rec *conn,
163 proxy_dir_conf *conf,
165 char *url, char *server_portstr)
170 apr_bucket_brigade *input_brigade;
171 apr_bucket_brigade *output_brigade;
173 apr_size_t bufsiz = 0;
175 char *send_body_chunk_buff;
177 apr_byte_t conn_reuse = 0;
180 int client_failed = 0;
181 int backend_failed = 0;
184 int request_ended = 0;
185 int headers_sent = 0;
187 apr_int32_t conn_poll_fd;
188 apr_pollfd_t *conn_poll;
189 proxy_server_conf *psf =
190 ap_get_module_config(r->server->module_config, &proxy_module);
191 apr_size_t maxsize = AJP_MSG_BUFFER_SZ;
193 apr_off_t content_length = 0;
194 int original_status = r->status;
195 const char *original_status_line = r->status_line;
197 if (psf->io_buffer_size_set)
198 maxsize = psf->io_buffer_size;
199 if (maxsize > AJP_MAX_BUFFER_SZ)
200 maxsize = AJP_MAX_BUFFER_SZ;
201 else if (maxsize < AJP_MSG_BUFFER_SZ)
202 maxsize = AJP_MSG_BUFFER_SZ;
203 maxsize = APR_ALIGN(maxsize, 1024);
206 * Send the AJP request to the remote server
209 /* send request headers */
210 status = ajp_send_header(conn->sock, r, maxsize, uri);
211 if (status != APR_SUCCESS) {
213 ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00868)
214 "request failed to %pI (%s)",
215 conn->worker->cp->addr,
216 conn->worker->s->hostname);
217 if (status == AJP_EOVERFLOW)
218 return HTTP_BAD_REQUEST;
221 * This is only non fatal when the method is idempotent. In this
222 * case we can dare to retry it with a different worker if we are
225 if (is_idempotent(r) == METHOD_IDEMPOTENT) {
226 return HTTP_SERVICE_UNAVAILABLE;
228 return HTTP_INTERNAL_SERVER_ERROR;
232 /* allocate an AJP message to store the data of the buckets */
234 status = ajp_alloc_data_msg(r->pool, &buff, &bufsiz, &msg);
235 if (status != APR_SUCCESS) {
236 /* We had a failure: Close connection to backend */
238 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00869)
239 "ajp_alloc_data_msg failed");
240 return HTTP_INTERNAL_SERVER_ERROR;
243 /* read the first bloc of data */
244 input_brigade = apr_brigade_create(p, r->connection->bucket_alloc);
245 tenc = apr_table_get(r->headers_in, "Transfer-Encoding");
246 if (tenc && (ap_casecmpstr(tenc, "chunked") == 0)) {
247 /* The AJP protocol does not want body data yet */
248 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00870) "request is chunked");
250 /* Get client provided Content-Length header */
251 content_length = get_content_length(r);
252 status = ap_get_brigade(r->input_filters, input_brigade,
253 AP_MODE_READBYTES, APR_BLOCK_READ,
254 maxsize - AJP_HEADER_SZ);
256 if (status != APR_SUCCESS) {
257 /* We had a failure: Close connection to backend */
259 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00871)
260 "ap_get_brigade failed");
261 apr_brigade_destroy(input_brigade);
262 return ap_map_http_request_error(status, HTTP_BAD_REQUEST);
266 if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(input_brigade))) {
267 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00872) "APR_BUCKET_IS_EOS");
270 /* Try to send something */
271 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00873)
272 "data to read (max %" APR_SIZE_T_FMT
273 " at %" APR_SIZE_T_FMT ")", bufsiz, msg->pos);
275 status = apr_brigade_flatten(input_brigade, buff, &bufsiz);
276 if (status != APR_SUCCESS) {
277 /* We had a failure: Close connection to backend */
279 apr_brigade_destroy(input_brigade);
280 ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00874)
281 "apr_brigade_flatten");
282 return HTTP_INTERNAL_SERVER_ERROR;
284 apr_brigade_cleanup(input_brigade);
286 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00875)
287 "got %" APR_SIZE_T_FMT " bytes of data", bufsiz);
289 status = ajp_send_data_msg(conn->sock, msg, bufsiz);
290 ajp_msg_log(r, msg, "First ajp_send_data_msg: ajp_ilink_send packet dump");
291 if (status != APR_SUCCESS) {
292 /* We had a failure: Close connection to backend */
294 apr_brigade_destroy(input_brigade);
295 ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00876)
296 "send failed to %pI (%s)",
297 conn->worker->cp->addr,
298 conn->worker->s->hostname);
300 * It is fatal when we failed to send a (part) of the request
303 return HTTP_INTERNAL_SERVER_ERROR;
305 conn->worker->s->transferred += bufsiz;
308 else if (content_length > 0) {
309 ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00877)
310 "read zero bytes, expecting"
311 " %" APR_OFF_T_FMT " bytes",
314 * We can only get here if the client closed the connection
315 * to us without sending the body.
316 * Now the connection is in the wrong state on the backend.
317 * Sending an empty data msg doesn't help either as it does
318 * not move this connection to the correct state on the backend
319 * for later resusage by the next request again.
320 * Close it to clean things up.
323 return HTTP_BAD_REQUEST;
327 /* read the response */
329 status = ajp_read_header(conn->sock, r, maxsize,
330 (ajp_msg_t **)&(conn->data));
331 if (status != APR_SUCCESS) {
332 /* We had a failure: Close connection to backend */
334 apr_brigade_destroy(input_brigade);
335 ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00878)
336 "read response failed from %pI (%s)",
337 conn->worker->cp->addr,
338 conn->worker->s->hostname);
340 /* If we had a successful cping/cpong and then a timeout
341 * we assume it is a request that cause a back-end timeout,
342 * but doesn't affect the whole worker.
344 if (APR_STATUS_IS_TIMEUP(status) &&
345 conn->worker->s->ping_timeout_set &&
346 conn->worker->s->ping_timeout >= 0) {
347 return HTTP_GATEWAY_TIME_OUT;
351 * This is only non fatal when we have not sent (parts) of a possible
352 * request body so far (we do not store it and thus cannot send it
353 * again) and the method is idempotent. In this case we can dare to
354 * retry it with a different worker if we are a balancer member.
356 if (!send_body && (is_idempotent(r) == METHOD_IDEMPOTENT)) {
357 return HTTP_SERVICE_UNAVAILABLE;
359 return HTTP_INTERNAL_SERVER_ERROR;
361 /* parse the reponse */
362 result = ajp_parse_type(r, conn->data);
363 output_brigade = apr_brigade_create(p, r->connection->bucket_alloc);
366 * Prepare apr_pollfd_t struct for possible later check if there is currently
367 * data available from the backend (do not flush response to client)
368 * or not (flush response to client)
370 conn_poll = apr_pcalloc(p, sizeof(apr_pollfd_t));
371 conn_poll->reqevents = APR_POLLIN;
372 conn_poll->desc_type = APR_POLL_SOCKET;
373 conn_poll->desc.s = conn->sock;
378 case CMD_AJP13_GET_BODY_CHUNK:
380 if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(input_brigade))) {
381 /* This is the end */
384 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00879)
385 "APR_BUCKET_IS_EOS");
387 status = ap_get_brigade(r->input_filters, input_brigade,
390 maxsize - AJP_HEADER_SZ);
391 if (status != APR_SUCCESS) {
392 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00880)
393 "ap_get_brigade failed");
394 if (APR_STATUS_IS_TIMEUP(status)) {
395 rv = HTTP_REQUEST_TIME_OUT;
397 else if (status == AP_FILTER_ERROR) {
398 rv = AP_FILTER_ERROR;
404 status = apr_brigade_flatten(input_brigade, buff,
406 apr_brigade_cleanup(input_brigade);
407 if (status != APR_SUCCESS) {
408 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00881)
409 "apr_brigade_flatten failed");
410 rv = HTTP_INTERNAL_SERVER_ERROR;
417 /* will go in ajp_send_data_msg */
418 status = ajp_send_data_msg(conn->sock, msg, bufsiz);
419 ajp_msg_log(r, msg, "ajp_send_data_msg after CMD_AJP13_GET_BODY_CHUNK: ajp_ilink_send packet dump");
420 if (status != APR_SUCCESS) {
421 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00882)
422 "ajp_send_data_msg failed");
426 conn->worker->s->transferred += bufsiz;
429 * something is wrong TC asks for more body but we are
430 * already at the end of the body data
432 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00883)
433 "ap_proxy_ajp_request error read after end");
437 case CMD_AJP13_SEND_HEADERS:
439 /* Do not send anything to the client.
440 * Backend already send us the headers.
443 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00884)
444 "Backend sent headers twice.");
447 /* AJP13_SEND_HEADERS: process them */
448 status = ajp_parse_header(r, conf, conn->data);
449 if (status != APR_SUCCESS) {
452 else if ((r->status == 401) && conf->error_override) {
454 const char *wa = "WWW-Authenticate";
455 if ((buf = apr_table_get(r->headers_out, wa))) {
456 apr_table_set(r->err_headers_out, wa, buf);
458 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00885)
459 "ap_proxy_ajp_request: origin server "
460 "sent 401 without WWW-Authenticate header");
465 case CMD_AJP13_SEND_BODY_CHUNK:
466 /* AJP13_SEND_BODY_CHUNK: piece of data */
467 status = ajp_parse_data(r, conn->data, &size, &send_body_chunk_buff);
468 if (status == APR_SUCCESS) {
469 /* If we are overriding the errors, we can't put the content
470 * of the page into the brigade.
472 if (!conf->error_override || !ap_is_HTTP_ERROR(r->status)) {
473 /* AJP13_SEND_BODY_CHUNK with zero length
474 * is explicit flush message
478 e = apr_bucket_flush_create(r->connection->bucket_alloc);
479 APR_BRIGADE_INSERT_TAIL(output_brigade, e);
482 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00886)
483 "Ignoring flush message "
484 "received before headers");
490 /* Handle the case where the error document is itself reverse
491 * proxied and was successful. We must maintain any previous
492 * error status so that an underlying error (eg HTTP_NOT_FOUND)
493 * doesn't become an HTTP_OK.
495 if (conf->error_override && !ap_is_HTTP_ERROR(r->status)
496 && ap_is_HTTP_ERROR(original_status)) {
497 r->status = original_status;
498 r->status_line = original_status_line;
501 e = apr_bucket_transient_create(send_body_chunk_buff, size,
502 r->connection->bucket_alloc);
503 APR_BRIGADE_INSERT_TAIL(output_brigade, e);
505 if ((conn->worker->s->flush_packets == flush_on) ||
506 ((conn->worker->s->flush_packets == flush_auto) &&
507 ((rv = apr_poll(conn_poll, 1, &conn_poll_fd,
508 conn->worker->s->flush_wait))
510 APR_STATUS_IS_TIMEUP(rv))) {
511 e = apr_bucket_flush_create(r->connection->bucket_alloc);
512 APR_BRIGADE_INSERT_TAIL(output_brigade, e);
514 apr_brigade_length(output_brigade, 0, &bb_len);
516 conn->worker->s->read += bb_len;
519 if (ap_pass_brigade(r->output_filters,
520 output_brigade) != APR_SUCCESS) {
521 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00887)
522 "error processing body.%s",
523 r->connection->aborted ?
524 " Client aborted connection." : "");
528 apr_brigade_cleanup(output_brigade);
536 case CMD_AJP13_END_RESPONSE:
537 /* If we are overriding the errors, we must not send anything to
538 * the client, especially as the brigade already contains headers.
539 * So do nothing here, and it will be cleaned up below.
541 status = ajp_parse_reuse(r, conn->data, &conn_reuse);
542 if (status != APR_SUCCESS) {
545 if (!conf->error_override || !ap_is_HTTP_ERROR(r->status)) {
546 e = apr_bucket_eos_create(r->connection->bucket_alloc);
547 APR_BRIGADE_INSERT_TAIL(output_brigade, e);
548 if (ap_pass_brigade(r->output_filters,
549 output_brigade) != APR_SUCCESS) {
550 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00888)
551 "error processing end");
554 /* XXX: what about flush here? See mod_jk */
565 * If connection has been aborted by client: Stop working.
566 * Pretend we are done (data_sent) to avoid further processing.
568 if (r->connection->aborted) {
569 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02821)
570 "client connection aborted");
571 /* no response yet (or ever), set status for access log */
573 r->status = HTTP_BAD_REQUEST;
582 * We either have finished successfully or we failed.
585 if ((result == CMD_AJP13_END_RESPONSE)
586 || backend_failed || client_failed)
589 /* read the response */
590 status = ajp_read_header(conn->sock, r, maxsize,
591 (ajp_msg_t **)&(conn->data));
592 if (status != APR_SUCCESS) {
594 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00889)
595 "ajp_read_header failed");
598 result = ajp_parse_type(r, conn->data);
600 apr_brigade_destroy(input_brigade);
603 * Clear output_brigade to remove possible buckets that remained there
606 apr_brigade_cleanup(output_brigade);
608 if (backend_failed || client_failed) {
609 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00890)
610 "Processing of request failed backend: %i, client: %i",
611 backend_failed, client_failed);
612 /* We had a failure: Close connection to backend */
615 /* Return DONE to avoid error messages being added to the stream */
619 else if (!request_ended) {
620 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00891)
621 "Processing of request didn't terminate cleanly");
622 /* We had a failure: Close connection to backend */
626 /* Return DONE to avoid error messages being added to the stream */
630 else if (!conn_reuse) {
631 /* Our backend signalled connection close */
635 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00892)
636 "got response from %pI (%s)",
637 conn->worker->cp->addr,
638 conn->worker->s->hostname);
640 if (conf->error_override && ap_is_HTTP_ERROR(r->status)) {
641 /* clear r->status for override error, otherwise ErrorDocument
642 * thinks that this is a recursive error, and doesn't find the
648 * prevent proxy_handler() from treating this as an
651 apr_table_setn(r->notes, "proxy-error-override", "1");
658 if (backend_failed) {
659 ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00893)
660 "dialog to %pI (%s) failed",
661 conn->worker->cp->addr,
662 conn->worker->s->hostname);
664 * If we already send data, signal a broken backend connection
665 * upwards in the chain.
668 ap_proxy_backend_broke(r, output_brigade);
669 } else if (!send_body && (is_idempotent(r) == METHOD_IDEMPOTENT)) {
671 * This is only non fatal when we have not send (parts) of a possible
672 * request body so far (we do not store it and thus cannot send it
673 * again) and the method is idempotent. In this case we can dare to
674 * retry it with a different worker if we are a balancer member.
676 rv = HTTP_SERVICE_UNAVAILABLE;
678 /* If we had a successful cping/cpong and then a timeout
679 * we assume it is a request that cause a back-end timeout,
680 * but doesn't affect the whole worker.
682 if (APR_STATUS_IS_TIMEUP(status) &&
683 conn->worker->s->ping_timeout_set &&
684 conn->worker->s->ping_timeout >= 0) {
685 apr_table_setn(r->notes, "proxy_timedout", "1");
686 rv = HTTP_GATEWAY_TIME_OUT;
689 rv = HTTP_INTERNAL_SERVER_ERROR;
693 else if (client_failed) {
694 int level = (r->connection->aborted) ? APLOG_DEBUG : APLOG_ERR;
695 ap_log_rerror(APLOG_MARK, level, status, r, APLOGNO(02822)
696 "dialog with client %pI failed",
697 r->connection->client_addr);
699 rv = HTTP_BAD_REQUEST;
704 * Ensure that we sent an EOS bucket thru the filter chain, if we already
705 * have sent some data. Maybe ap_proxy_backend_broke was called and added
706 * one to the brigade already (no longer making it empty). So we should
707 * not do this in this case.
709 if (data_sent && !r->eos_sent && !r->connection->aborted
710 && APR_BRIGADE_EMPTY(output_brigade)) {
711 e = apr_bucket_eos_create(r->connection->bucket_alloc);
712 APR_BRIGADE_INSERT_TAIL(output_brigade, e);
715 /* If we have added something to the brigade above, send it */
716 if (!APR_BRIGADE_EMPTY(output_brigade)
717 && ap_pass_brigade(r->output_filters, output_brigade) != APR_SUCCESS) {
718 rv = AP_FILTER_ERROR;
721 apr_brigade_destroy(output_brigade);
723 if (apr_table_get(r->subprocess_env, "proxy-nokeepalive")) {
731 * This handles ajp:// URLs
733 static int proxy_ajp_handler(request_rec *r, proxy_worker *worker,
734 proxy_server_conf *conf,
735 char *url, const char *proxyname,
736 apr_port_t proxyport)
739 char server_portstr[32];
740 conn_rec *origin = NULL;
741 proxy_conn_rec *backend = NULL;
742 const char *scheme = "AJP";
744 proxy_dir_conf *dconf = ap_get_module_config(r->per_dir_config,
746 apr_pool_t *p = r->pool;
749 if (ap_casecmpstrn(url, "ajp:", 4) != 0) {
750 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00894) "declining URL %s", url);
754 uri = apr_palloc(p, sizeof(*uri));
755 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00895) "serving URL %s", url);
757 /* create space for state information */
758 status = ap_proxy_acquire_connection(scheme, &backend, worker,
763 ap_proxy_release_connection(scheme, backend, r->server);
774 /* Step One: Determine Who To Connect To */
775 status = ap_proxy_determine_connection(p, r, conf, worker, backend,
776 uri, &locurl, proxyname, proxyport,
778 sizeof(server_portstr));
783 /* Step Two: Make the Connection */
784 if (ap_proxy_connect_backend(scheme, backend, worker, r->server)) {
785 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00896)
786 "failed to make connection to backend: %s",
788 status = HTTP_SERVICE_UNAVAILABLE;
792 /* Handle CPING/CPONG */
793 if (worker->s->ping_timeout_set) {
794 if (worker->s->ping_timeout < 0) {
795 if (!ap_proxy_is_socket_connected(backend->sock)) {
797 ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(02534)
798 "socket check failed to %pI (%s)",
799 worker->cp->addr, worker->s->hostname);
800 status = HTTP_SERVICE_UNAVAILABLE;
806 status = ajp_handle_cping_cpong(backend->sock, r,
807 worker->s->ping_timeout);
809 * In case the CPING / CPONG failed for the first time we might be
810 * just out of luck and got a faulty backend connection, but the
811 * backend might be healthy nevertheless. So ensure that the backend
812 * TCP connection gets closed and try it once again.
814 if (status != APR_SUCCESS) {
816 ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00897)
817 "cping/cpong failed to %pI (%s)",
818 worker->cp->addr, worker->s->hostname);
819 status = HTTP_SERVICE_UNAVAILABLE;
825 /* Step Three: Process the Request */
826 status = ap_proxy_ajp_request(p, r, backend, origin, dconf, uri, locurl,
831 /* Do not close the socket */
832 ap_proxy_release_connection(scheme, backend, r->server);
836 static void ap_proxy_http_register_hook(apr_pool_t *p)
838 proxy_hook_scheme_handler(proxy_ajp_handler, NULL, NULL, APR_HOOK_FIRST);
839 proxy_hook_canon_handler(proxy_ajp_canon, NULL, NULL, APR_HOOK_FIRST);
842 AP_DECLARE_MODULE(proxy_ajp) = {
843 STANDARD20_MODULE_STUFF,
844 NULL, /* create per-directory config structure */
845 NULL, /* merge per-directory config structures */
846 NULL, /* create per-server config structure */
847 NULL, /* merge per-server config structures */
848 NULL, /* command apr_table_t */
849 ap_proxy_http_register_hook /* register hooks */