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_cstr_casecmpn(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 milliseconds 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;
196 const char *secret = NULL;
198 if (psf->io_buffer_size_set)
199 maxsize = psf->io_buffer_size;
200 if (maxsize > AJP_MAX_BUFFER_SZ)
201 maxsize = AJP_MAX_BUFFER_SZ;
202 else if (maxsize < AJP_MSG_BUFFER_SZ)
203 maxsize = AJP_MSG_BUFFER_SZ;
204 maxsize = APR_ALIGN(maxsize, 1024);
206 if (*conn->worker->s->secret)
207 secret = conn->worker->s->secret;
210 * Send the AJP request to the remote server
213 /* send request headers */
214 status = ajp_send_header(conn->sock, r, maxsize, uri, secret);
215 if (status != APR_SUCCESS) {
217 ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00868)
218 "request failed to %pI (%s)",
219 conn->worker->cp->addr,
220 conn->worker->s->hostname);
221 if (status == AJP_EOVERFLOW)
222 return HTTP_BAD_REQUEST;
225 * This is only non fatal when the method is idempotent. In this
226 * case we can dare to retry it with a different worker if we are
229 if (is_idempotent(r) == METHOD_IDEMPOTENT) {
230 return HTTP_SERVICE_UNAVAILABLE;
232 return HTTP_INTERNAL_SERVER_ERROR;
236 /* allocate an AJP message to store the data of the buckets */
238 status = ajp_alloc_data_msg(r->pool, &buff, &bufsiz, &msg);
239 if (status != APR_SUCCESS) {
240 /* We had a failure: Close connection to backend */
242 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00869)
243 "ajp_alloc_data_msg failed");
244 return HTTP_INTERNAL_SERVER_ERROR;
247 /* read the first bloc of data */
248 input_brigade = apr_brigade_create(p, r->connection->bucket_alloc);
249 tenc = apr_table_get(r->headers_in, "Transfer-Encoding");
250 if (tenc && (ap_cstr_casecmp(tenc, "chunked") == 0)) {
251 /* The AJP protocol does not want body data yet */
252 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00870) "request is chunked");
254 /* Get client provided Content-Length header */
255 content_length = get_content_length(r);
256 status = ap_get_brigade(r->input_filters, input_brigade,
257 AP_MODE_READBYTES, APR_BLOCK_READ,
258 maxsize - AJP_HEADER_SZ);
260 if (status != APR_SUCCESS) {
261 /* We had a failure: Close connection to backend */
263 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00871)
264 "ap_get_brigade failed");
265 apr_brigade_destroy(input_brigade);
266 return ap_map_http_request_error(status, HTTP_BAD_REQUEST);
270 if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(input_brigade))) {
271 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00872) "APR_BUCKET_IS_EOS");
274 /* Try to send something */
275 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00873)
276 "data to read (max %" APR_SIZE_T_FMT
277 " at %" APR_SIZE_T_FMT ")", bufsiz, msg->pos);
279 status = apr_brigade_flatten(input_brigade, buff, &bufsiz);
280 if (status != APR_SUCCESS) {
281 /* We had a failure: Close connection to backend */
283 apr_brigade_destroy(input_brigade);
284 ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00874)
285 "apr_brigade_flatten");
286 return HTTP_INTERNAL_SERVER_ERROR;
288 apr_brigade_cleanup(input_brigade);
290 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00875)
291 "got %" APR_SIZE_T_FMT " bytes of data", bufsiz);
293 status = ajp_send_data_msg(conn->sock, msg, bufsiz);
294 ajp_msg_log(r, msg, "First ajp_send_data_msg: ajp_ilink_send packet dump");
295 if (status != APR_SUCCESS) {
296 /* We had a failure: Close connection to backend */
298 apr_brigade_destroy(input_brigade);
299 ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00876)
300 "send failed to %pI (%s)",
301 conn->worker->cp->addr,
302 conn->worker->s->hostname);
304 * It is fatal when we failed to send a (part) of the request
307 return HTTP_INTERNAL_SERVER_ERROR;
309 conn->worker->s->transferred += bufsiz;
312 else if (content_length > 0) {
313 ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00877)
314 "read zero bytes, expecting"
315 " %" APR_OFF_T_FMT " bytes",
318 * We can only get here if the client closed the connection
319 * to us without sending the body.
320 * Now the connection is in the wrong state on the backend.
321 * Sending an empty data msg doesn't help either as it does
322 * not move this connection to the correct state on the backend
323 * for later resusage by the next request again.
324 * Close it to clean things up.
327 return HTTP_BAD_REQUEST;
331 /* read the response */
333 status = ajp_read_header(conn->sock, r, maxsize,
334 (ajp_msg_t **)&(conn->data));
335 if (status != APR_SUCCESS) {
336 /* We had a failure: Close connection to backend */
338 apr_brigade_destroy(input_brigade);
339 ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00878)
340 "read response failed from %pI (%s)",
341 conn->worker->cp->addr,
342 conn->worker->s->hostname);
344 /* If we had a successful cping/cpong and then a timeout
345 * we assume it is a request that cause a back-end timeout,
346 * but doesn't affect the whole worker.
348 if (APR_STATUS_IS_TIMEUP(status) &&
349 conn->worker->s->ping_timeout_set) {
350 return HTTP_GATEWAY_TIME_OUT;
354 * This is only non fatal when we have not sent (parts) of a possible
355 * request body so far (we do not store it and thus cannot send it
356 * again) and the method is idempotent. In this case we can dare to
357 * retry it with a different worker if we are a balancer member.
359 if (!send_body && (is_idempotent(r) == METHOD_IDEMPOTENT)) {
360 return HTTP_SERVICE_UNAVAILABLE;
362 return HTTP_INTERNAL_SERVER_ERROR;
364 /* parse the response */
365 result = ajp_parse_type(r, conn->data);
366 output_brigade = apr_brigade_create(p, r->connection->bucket_alloc);
369 * Prepare apr_pollfd_t struct for possible later check if there is currently
370 * data available from the backend (do not flush response to client)
371 * or not (flush response to client)
373 conn_poll = apr_pcalloc(p, sizeof(apr_pollfd_t));
374 conn_poll->reqevents = APR_POLLIN;
375 conn_poll->desc_type = APR_POLL_SOCKET;
376 conn_poll->desc.s = conn->sock;
381 case CMD_AJP13_GET_BODY_CHUNK:
383 if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(input_brigade))) {
384 /* This is the end */
387 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00879)
388 "APR_BUCKET_IS_EOS");
390 status = ap_get_brigade(r->input_filters, input_brigade,
393 maxsize - AJP_HEADER_SZ);
394 if (status != APR_SUCCESS) {
395 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00880)
396 "ap_get_brigade failed");
397 if (APR_STATUS_IS_TIMEUP(status)) {
398 rv = HTTP_REQUEST_TIME_OUT;
400 else if (status == AP_FILTER_ERROR) {
401 rv = AP_FILTER_ERROR;
407 status = apr_brigade_flatten(input_brigade, buff,
409 apr_brigade_cleanup(input_brigade);
410 if (status != APR_SUCCESS) {
411 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00881)
412 "apr_brigade_flatten failed");
413 rv = HTTP_INTERNAL_SERVER_ERROR;
420 /* will go in ajp_send_data_msg */
421 status = ajp_send_data_msg(conn->sock, msg, bufsiz);
422 ajp_msg_log(r, msg, "ajp_send_data_msg after CMD_AJP13_GET_BODY_CHUNK: ajp_ilink_send packet dump");
423 if (status != APR_SUCCESS) {
424 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00882)
425 "ajp_send_data_msg failed");
429 conn->worker->s->transferred += bufsiz;
432 * something is wrong TC asks for more body but we are
433 * already at the end of the body data
435 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00883)
436 "ap_proxy_ajp_request error read after end");
440 case CMD_AJP13_SEND_HEADERS:
442 /* Do not send anything to the client.
443 * Backend already send us the headers.
446 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00884)
447 "Backend sent headers twice.");
450 /* AJP13_SEND_HEADERS: process them */
451 status = ajp_parse_header(r, conf, conn->data);
452 if (status != APR_SUCCESS) {
455 else if ((r->status == 401) && conf->error_override) {
457 const char *wa = "WWW-Authenticate";
458 if ((buf = apr_table_get(r->headers_out, wa))) {
459 apr_table_set(r->err_headers_out, wa, buf);
461 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00885)
462 "ap_proxy_ajp_request: origin server "
463 "sent 401 without WWW-Authenticate header");
468 case CMD_AJP13_SEND_BODY_CHUNK:
469 /* AJP13_SEND_BODY_CHUNK: piece of data */
470 status = ajp_parse_data(r, conn->data, &size, &send_body_chunk_buff);
471 if (status == APR_SUCCESS) {
472 /* If we are overriding the errors, we can't put the content
473 * of the page into the brigade.
475 if (!conf->error_override || !ap_is_HTTP_ERROR(r->status)) {
476 /* AJP13_SEND_BODY_CHUNK with zero length
477 * is explicit flush message
481 e = apr_bucket_flush_create(r->connection->bucket_alloc);
482 APR_BRIGADE_INSERT_TAIL(output_brigade, e);
485 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00886)
486 "Ignoring flush message "
487 "received before headers");
493 /* Handle the case where the error document is itself reverse
494 * proxied and was successful. We must maintain any previous
495 * error status so that an underlying error (eg HTTP_NOT_FOUND)
496 * doesn't become an HTTP_OK.
498 if (conf->error_override && !ap_is_HTTP_ERROR(r->status)
499 && ap_is_HTTP_ERROR(original_status)) {
500 r->status = original_status;
501 r->status_line = original_status_line;
504 e = apr_bucket_transient_create(send_body_chunk_buff, size,
505 r->connection->bucket_alloc);
506 APR_BRIGADE_INSERT_TAIL(output_brigade, e);
508 if ((conn->worker->s->flush_packets == flush_on) ||
509 ((conn->worker->s->flush_packets == flush_auto) &&
510 ((rv = apr_poll(conn_poll, 1, &conn_poll_fd,
511 conn->worker->s->flush_wait))
513 APR_STATUS_IS_TIMEUP(rv))) {
514 e = apr_bucket_flush_create(r->connection->bucket_alloc);
515 APR_BRIGADE_INSERT_TAIL(output_brigade, e);
517 apr_brigade_length(output_brigade, 0, &bb_len);
519 conn->worker->s->read += bb_len;
522 if (ap_pass_brigade(r->output_filters,
523 output_brigade) != APR_SUCCESS) {
524 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00887)
525 "error processing body.%s",
526 r->connection->aborted ?
527 " Client aborted connection." : "");
531 apr_brigade_cleanup(output_brigade);
539 case CMD_AJP13_END_RESPONSE:
540 /* If we are overriding the errors, we must not send anything to
541 * the client, especially as the brigade already contains headers.
542 * So do nothing here, and it will be cleaned up below.
544 status = ajp_parse_reuse(r, conn->data, &conn_reuse);
545 if (status != APR_SUCCESS) {
548 if (!conf->error_override || !ap_is_HTTP_ERROR(r->status)) {
549 e = apr_bucket_eos_create(r->connection->bucket_alloc);
550 APR_BRIGADE_INSERT_TAIL(output_brigade, e);
551 if (ap_pass_brigade(r->output_filters,
552 output_brigade) != APR_SUCCESS) {
553 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00888)
554 "error processing end");
557 /* XXX: what about flush here? See mod_jk */
568 * If connection has been aborted by client: Stop working.
569 * Pretend we are done (data_sent) to avoid further processing.
571 if (r->connection->aborted) {
572 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02821)
573 "client connection aborted");
574 /* no response yet (or ever), set status for access log */
576 r->status = HTTP_BAD_REQUEST;
585 * We either have finished successfully or we failed.
588 if ((result == CMD_AJP13_END_RESPONSE)
589 || backend_failed || client_failed)
592 /* read the response */
593 status = ajp_read_header(conn->sock, r, maxsize,
594 (ajp_msg_t **)&(conn->data));
595 if (status != APR_SUCCESS) {
597 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00889)
598 "ajp_read_header failed");
601 result = ajp_parse_type(r, conn->data);
603 apr_brigade_destroy(input_brigade);
606 * Clear output_brigade to remove possible buckets that remained there
609 apr_brigade_cleanup(output_brigade);
611 if (backend_failed || client_failed) {
612 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00890)
613 "Processing of request failed backend: %i, client: %i",
614 backend_failed, client_failed);
615 /* We had a failure: Close connection to backend */
618 /* Return DONE to avoid error messages being added to the stream */
622 else if (!request_ended) {
623 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00891)
624 "Processing of request didn't terminate cleanly");
625 /* We had a failure: Close connection to backend */
629 /* Return DONE to avoid error messages being added to the stream */
633 else if (!conn_reuse) {
634 /* Our backend signalled connection close */
638 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00892)
639 "got response from %pI (%s)",
640 conn->worker->cp->addr,
641 conn->worker->s->hostname);
643 if (conf->error_override && ap_is_HTTP_ERROR(r->status)) {
644 /* clear r->status for override error, otherwise ErrorDocument
645 * thinks that this is a recursive error, and doesn't find the
651 * prevent proxy_handler() from treating this as an
654 apr_table_setn(r->notes, "proxy-error-override", "1");
661 if (backend_failed) {
662 ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00893)
663 "dialog to %pI (%s) failed",
664 conn->worker->cp->addr,
665 conn->worker->s->hostname);
667 * If we already send data, signal a broken backend connection
668 * upwards in the chain.
671 ap_proxy_backend_broke(r, output_brigade);
672 } else if (!send_body && (is_idempotent(r) == METHOD_IDEMPOTENT)) {
674 * This is only non fatal when we have not send (parts) of a possible
675 * request body so far (we do not store it and thus cannot send it
676 * again) and the method is idempotent. In this case we can dare to
677 * retry it with a different worker if we are a balancer member.
679 rv = HTTP_SERVICE_UNAVAILABLE;
681 /* If we had a successful cping/cpong and then a timeout
682 * we assume it is a request that cause a back-end timeout,
683 * but doesn't affect the whole worker.
685 if (APR_STATUS_IS_TIMEUP(status) &&
686 conn->worker->s->ping_timeout_set) {
687 apr_table_setn(r->notes, "proxy_timedout", "1");
688 rv = HTTP_GATEWAY_TIME_OUT;
691 rv = HTTP_INTERNAL_SERVER_ERROR;
695 else if (client_failed) {
696 int level = (r->connection->aborted) ? APLOG_DEBUG : APLOG_ERR;
697 ap_log_rerror(APLOG_MARK, level, status, r, APLOGNO(02822)
698 "dialog with client %pI failed",
699 r->connection->client_addr);
701 rv = HTTP_BAD_REQUEST;
706 * Ensure that we sent an EOS bucket thru the filter chain, if we already
707 * have sent some data. Maybe ap_proxy_backend_broke was called and added
708 * one to the brigade already (no longer making it empty). So we should
709 * not do this in this case.
711 if (data_sent && !r->eos_sent && !r->connection->aborted
712 && APR_BRIGADE_EMPTY(output_brigade)) {
713 e = apr_bucket_eos_create(r->connection->bucket_alloc);
714 APR_BRIGADE_INSERT_TAIL(output_brigade, e);
717 /* If we have added something to the brigade above, send it */
718 if (!APR_BRIGADE_EMPTY(output_brigade)
719 && ap_pass_brigade(r->output_filters, output_brigade) != APR_SUCCESS) {
720 rv = AP_FILTER_ERROR;
723 apr_brigade_destroy(output_brigade);
725 if (apr_table_get(r->subprocess_env, "proxy-nokeepalive")) {
733 * This handles ajp:// URLs
735 static int proxy_ajp_handler(request_rec *r, proxy_worker *worker,
736 proxy_server_conf *conf,
737 char *url, const char *proxyname,
738 apr_port_t proxyport)
741 char server_portstr[32];
742 conn_rec *origin = NULL;
743 proxy_conn_rec *backend = NULL;
744 const char *scheme = "AJP";
746 proxy_dir_conf *dconf = ap_get_module_config(r->per_dir_config,
748 apr_pool_t *p = r->pool;
751 if (ap_cstr_casecmpn(url, "ajp:", 4) != 0) {
752 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00894) "declining URL %s", url);
756 uri = apr_palloc(p, sizeof(*uri));
757 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00895) "serving URL %s", url);
759 /* create space for state information */
760 status = ap_proxy_acquire_connection(scheme, &backend, worker,
765 ap_proxy_release_connection(scheme, backend, r->server);
776 /* Step One: Determine Who To Connect To */
777 status = ap_proxy_determine_connection(p, r, conf, worker, backend,
778 uri, &locurl, proxyname, proxyport,
780 sizeof(server_portstr));
785 /* Step Two: Make the Connection */
786 if (ap_proxy_check_backend(scheme, backend, r->server, 1) &&
787 ap_proxy_connect_backend(scheme, backend, worker, r->server)) {
788 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00896)
789 "failed to make connection to backend: %s",
791 status = HTTP_SERVICE_UNAVAILABLE;
795 /* Handle CPING/CPONG */
796 if (worker->s->ping_timeout_set) {
797 status = ajp_handle_cping_cpong(backend->sock, r,
798 worker->s->ping_timeout);
800 * In case the CPING / CPONG failed for the first time we might be
801 * just out of luck and got a faulty backend connection, but the
802 * backend might be healthy nevertheless. So ensure that the backend
803 * TCP connection gets closed and try it once again.
805 if (status != APR_SUCCESS) {
807 ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00897)
808 "cping/cpong failed to %pI (%s)",
809 worker->cp->addr, worker->s->hostname);
810 status = HTTP_SERVICE_UNAVAILABLE;
815 /* Step Three: Process the Request */
816 status = ap_proxy_ajp_request(p, r, backend, origin, dconf, uri, locurl,
821 /* Do not close the socket */
822 ap_proxy_release_connection(scheme, backend, r->server);
826 static void ap_proxy_http_register_hook(apr_pool_t *p)
828 proxy_hook_scheme_handler(proxy_ajp_handler, NULL, NULL, APR_HOOK_FIRST);
829 proxy_hook_canon_handler(proxy_ajp_canon, NULL, NULL, APR_HOOK_FIRST);
832 AP_DECLARE_MODULE(proxy_ajp) = {
833 STANDARD20_MODULE_STUFF,
834 NULL, /* create per-directory config structure */
835 NULL, /* merge per-directory config structures */
836 NULL, /* create per-server config structure */
837 NULL, /* merge per-server config structures */
838 NULL, /* command apr_table_t */
839 ap_proxy_http_register_hook /* register hooks */