/* Licensed to the Apache Software Foundation (ASF) under one or more *contributorlicenseagreements.SeetheNOTICEfiledistributedwith *thisworkforadditionalinformationregardingcopyrightownership. *TheASFlicensesthisfiletoYouundertheApacheLicense,Version2.0 *(the"License");youmaynotusethisfileexceptincompliancewith *theLicense.YoumayobtainacopyoftheLicenseat * *http://www.apache.org/licenses/LICENSE-2.0 * *Unlessrequiredbyapplicablelaworagreedtoinwriting,software *distributedundertheLicenseisdistributedonan"ASIS"BASIS, *WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied. *SeetheLicenseforthespecificlanguagegoverningpermissionsand *limitationsundertheLicense.
*/
/* allocate an AJP message to store the data of the buckets */
bufsiz = maxsize;
status = ajp_alloc_data_msg(r->pool, &buff, &bufsiz, &msg); if (status != APR_SUCCESS) { /* We had a failure: Close connection to backend */
conn->close = 1;
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00869) "ajp_alloc_data_msg failed"); return HTTP_INTERNAL_SERVER_ERROR;
}
/* read the first block of data */
input_brigade = apr_brigade_create(p, r->connection->bucket_alloc);
tenc = apr_table_get(r->headers_in, "Transfer-Encoding"); if (tenc) { if (ap_cstr_casecmp(tenc, "chunked") == 0) { /* The AJP protocol does not want body data yet */
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00870) "request is chunked");
} else {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10396) "%s Transfer-Encoding is not supported",
tenc); /* We had a failure: Close connection to backend */
conn->close = 1; return HTTP_INTERNAL_SERVER_ERROR;
}
} else { /* Get client provided Content-Length header */
content_length = get_content_length(r); if (content_length < 0) {
status = APR_EINVAL;
} else {
status = ap_get_brigade(r->input_filters, input_brigade,
AP_MODE_READBYTES, APR_BLOCK_READ,
maxsize - AJP_HEADER_SZ);
} if (status != APR_SUCCESS) { /* We had a failure: Close connection to backend */
conn->close = 1;
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00871) "ap_get_brigade failed");
apr_brigade_destroy(input_brigade); return ap_map_http_request_error(status, HTTP_BAD_REQUEST);
}
/* have something */ if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(input_brigade))) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00872) "APR_BUCKET_IS_EOS");
}
/* Try to send something */
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00873) "data to read (max %" APR_SIZE_T_FMT " at %" APR_SIZE_T_FMT ")", bufsiz, msg->pos);
status = apr_brigade_flatten(input_brigade, buff, &bufsiz); if (status != APR_SUCCESS) { /* We had a failure: Close connection to backend */
conn->close = 1;
apr_brigade_destroy(input_brigade);
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00874) "apr_brigade_flatten"); return HTTP_INTERNAL_SERVER_ERROR;
}
apr_brigade_cleanup(input_brigade);
/* read the response */
conn->data = NULL;
status = ajp_read_header(conn->sock, r, maxsize,
(ajp_msg_t **)&(conn->data)); if (status != APR_SUCCESS) { /* We had a failure: Close connection to backend */
conn->close = 1;
apr_brigade_destroy(input_brigade);
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00878) "read response failed from %pI (%s:%hu)",
conn->addr, conn->hostname, conn->port);
/* If we had a successful cping/cpong and then a timeout *weassumeitisarequestthatcauseaback-endtimeout, *butdoesn'taffectthewholeworker.
*/ if (APR_STATUS_IS_TIMEUP(status) &&
conn->worker->s->ping_timeout_set) { return HTTP_GATEWAY_TIME_OUT;
}
bufsiz = maxsize; for (;;) { switch (result) { case CMD_AJP13_GET_BODY_CHUNK: if (havebody) { if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(input_brigade))) { /* This is the end */
bufsiz = 0;
havebody = 0;
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00879) "APR_BUCKET_IS_EOS");
} else {
status = ap_get_brigade(r->input_filters, input_brigade,
AP_MODE_READBYTES,
APR_BLOCK_READ,
maxsize - AJP_HEADER_SZ); if (status != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00880) "ap_get_brigade failed"); if (APR_STATUS_IS_TIMEUP(status)) {
rv = HTTP_REQUEST_TIME_OUT;
} elseif (status == AP_FILTER_ERROR) {
rv = AP_FILTER_ERROR;
}
client_failed = 1; break;
}
bufsiz = maxsize;
status = apr_brigade_flatten(input_brigade, buff,
&bufsiz);
apr_brigade_cleanup(input_brigade); if (status != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00881) "apr_brigade_flatten failed");
rv = HTTP_INTERNAL_SERVER_ERROR;
client_failed = 1; break;
}
}
ajp_msg_reset(msg); /* will go in ajp_send_data_msg */
status = ajp_send_data_msg(conn->sock, msg, bufsiz);
ajp_msg_log(r, msg, "ajp_send_data_msg after CMD_AJP13_GET_BODY_CHUNK: ajp_ilink_send packet dump"); if (status != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, APLOGNO(00882) "ajp_send_data_msg failed");
backend_failed = 1; break;
}
conn->worker->s->transferred += bufsiz;
} else { /* *somethingiswrongTCasksformorebodybutweare *alreadyattheendofthebodydata
*/
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00883) "ap_proxy_ajp_request error read after end");
backend_failed = 1;
} break; case CMD_AJP13_SEND_HEADERS: if (headers_sent) { /* Do not send anything to the client. *Backendalreadysendustheheaders.
*/
backend_failed = 1;
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00884) "Backend sent headers twice."); break;
} /* AJP13_SEND_HEADERS: process them */
status = ajp_parse_header(r, conf, conn->data); if (status != APR_SUCCESS) {
backend_failed = 1;
} elseif ((r->status == 401) && conf->error_override) { constchar *buf; constchar *wa = "WWW-Authenticate"; if ((buf = apr_table_get(r->headers_out, wa))) {
apr_table_set(r->err_headers_out, wa, buf);
} else {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00885) "ap_proxy_ajp_request: origin server " "sent 401 without WWW-Authenticate header");
}
}
headers_sent = 1; break; case CMD_AJP13_SEND_BODY_CHUNK: /* AJP13_SEND_BODY_CHUNK: piece of data */
status = ajp_parse_data(r, conn->data, &size, &send_body_chunk_buff); if (status == APR_SUCCESS) { /* If we are overriding the errors, we can't put the content *ofthepageintothebrigade.
*/ if (!ap_proxy_should_override(conf, r->status)) { /* AJP13_SEND_BODY_CHUNK with zero length *isexplicitflushmessage
*/ if (size == 0) { if (headers_sent) {
e = apr_bucket_flush_create(r->connection->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(output_brigade, e);
} else {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00886) "Ignoring flush message " "received before headers");
}
} else {
apr_status_t rv;
/* Handle the case where the error document is itself reverse *proxiedandwassuccessful.Wemustmaintainanyprevious *errorstatussothatanunderlyingerror(egHTTP_NOT_FOUND) *doesn'tbecomeanHTTP_OK.
*/ if (ap_proxy_should_override(conf, original_status)) {
r->status = original_status;
r->status_line = original_status_line;
}
e = apr_bucket_transient_create(send_body_chunk_buff, size,
r->connection->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(output_brigade, e);
if ((conn->worker->s->flush_packets == flush_on) ||
((conn->worker->s->flush_packets == flush_auto) &&
((rv = apr_poll(conn_poll, 1, &conn_poll_fd,
conn->worker->s->flush_wait))
!= APR_SUCCESS) &&
APR_STATUS_IS_TIMEUP(rv))) {
e = apr_bucket_flush_create(r->connection->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(output_brigade, e);
}
apr_brigade_length(output_brigade, 0, &bb_len); if (bb_len != -1)
conn->worker->s->read += bb_len;
} if (headers_sent) { if (ap_pass_brigade(r->output_filters,
output_brigade) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00887) "error processing body.%s",
r->connection->aborted ? " Client aborted connection." : "");
client_failed = 1;
}
data_sent = 1;
apr_brigade_cleanup(output_brigade);
}
}
} else {
backend_failed = 1;
} break; case CMD_AJP13_END_RESPONSE: /* If we are overriding the errors, we must not send anything to *theclient,especiallyasthebrigadealreadycontainsheaders. *Sodonothinghere,anditwillbecleanedupbelow.
*/
status = ajp_parse_reuse(r, conn->data, &conn_reuse); if (status != APR_SUCCESS) {
backend_failed = 1;
} if (!ap_proxy_should_override(conf, r->status)) {
e = apr_bucket_eos_create(r->connection->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(output_brigade, e); if (ap_pass_brigade(r->output_filters,
output_brigade) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00888) "error processing end");
client_failed = 1;
} /* XXX: what about flush here? See mod_jk */
data_sent = 1;
}
request_ended = 1; break; default:
backend_failed = 1; break;
}
/* *Ifconnectionhasbeenabortedbyclient:Stopworking. *Pretendwearedone(data_sent)toavoidfurtherprocessing.
*/ if (r->connection->aborted) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02821) "client connection aborted"); /* no response yet (or ever), set status for access log */ if (!headers_sent) {
r->status = HTTP_BAD_REQUEST;
}
client_failed = 1; /* return DONE */
data_sent = 1; break;
}
/* If we have added something to the brigade above, send it */ if (!APR_BRIGADE_EMPTY(output_brigade)
&& ap_pass_brigade(r->output_filters, output_brigade) != APR_SUCCESS) {
rv = AP_FILTER_ERROR;
}
apr_brigade_destroy(output_brigade);
if (apr_table_get(r->subprocess_env, "proxy-nokeepalive")) {
conn->close = 1;
}
/* create space for state information */
status = ap_proxy_acquire_connection(scheme, &backend, worker,
r->server); if (status != OK) { if (backend) {
backend->close = 1;
ap_proxy_release_connection(scheme, backend, r->server);
} return status;
}
backend->is_ssl = 0;
backend->close = 0;
retry = 0; while (retry < 2) { char *locurl = url; /* Step One: Determine Who To Connect To */
status = ap_proxy_determine_connection(p, r, conf, worker, backend,
uri, &locurl, proxyname, proxyport,
server_portstr, sizeof(server_portstr));
if (status != OK) break;
/* Step Two: Make the Connection */ if (ap_proxy_check_connection(scheme, backend, r->server, 0,
PROXY_CHECK_CONN_EMPTY)
&& ap_proxy_connect_backend(scheme, backend, worker,
r->server)) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00896) "failed to make connection to backend: %s",
backend->hostname);
status = HTTP_SERVICE_UNAVAILABLE; break;
}
/* Handle CPING/CPONG */ if (worker->s->ping_timeout_set) {
status = ajp_handle_cping_cpong(backend->sock, r,
worker->s->ping_timeout); /* *IncasetheCPING/CPONGfailedforthefirsttimewemightbe *justoutofluckandgotafaultybackendconnection,butthe *backendmightbehealthynevertheless.Soensurethatthebackend *TCPconnectiongetsclosedandtryitonceagain.
*/ if (status != APR_SUCCESS) {
backend->close = 1;
ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(00897) "cping/cpong failed to %pI (%s:%hu)",
backend->addr, backend->hostname, backend->port);
status = HTTP_SERVICE_UNAVAILABLE;
retry++; continue;
}
} /* Step Three: Process the Request */
status = ap_proxy_ajp_request(p, r, backend, origin, dconf, uri, locurl,
server_portstr); break;
}
/* Do not close the socket */
ap_proxy_release_connection(scheme, backend, r->server); return status;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.