X-Git-Url: https://granicus.if.org/sourcecode?a=blobdiff_plain;f=modules%2Fproxy%2Fmod_proxy_http.c;h=7822366c0fae1756a480b900954b4cb7dc943e60;hb=2af2fa44ad916dd01102764e3a7674a450622028;hp=b3186b59f814dd05f13ea12ecc87eaece562c538;hpb=394e5594d60f65a687e2bad9a848af8fed70a55e;p=apache diff --git a/modules/proxy/mod_proxy_http.c b/modules/proxy/mod_proxy_http.c index b3186b59f8..7822366c0f 100644 --- a/modules/proxy/mod_proxy_http.c +++ b/modules/proxy/mod_proxy_http.c @@ -62,7 +62,7 @@ static int proxy_http_canon(request_rec *r, char *url) port = def_port; err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port); if (err) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, + ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01083) "error parsing URL %s: %s", url, err); return HTTP_BAD_REQUEST; } @@ -267,7 +267,7 @@ static int pass_brigade(apr_bucket_alloc_t *bucket_alloc, p_conn->worker->s->transferred += transferred; status = ap_pass_brigade(origin->output_filters, bb); if (status != APR_SUCCESS) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, + ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(01084) "pass request body failed to %pI (%s)", p_conn->addr, p_conn->hostname); if (origin->aborted) { @@ -440,7 +440,7 @@ static int stream_reqbody_cl(apr_pool_t *p, status = apr_strtoff(&cl_val, old_cl_val, &endstr, 10); if (status || *endstr || endstr == old_cl_val || cl_val < 0) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, + ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(01085) "could not parse request Content-Length (%s)", old_cl_val); return HTTP_BAD_REQUEST; @@ -477,7 +477,7 @@ static int stream_reqbody_cl(apr_pool_t *p, * Prevents HTTP Response Splitting. */ if (bytes_streamed > cl_val) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, + ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01086) "read more bytes of request body than expected " "(got %" APR_OFF_T_FMT ", expected %" APR_OFF_T_FMT ")", bytes_streamed, cl_val); @@ -530,7 +530,7 @@ static int stream_reqbody_cl(apr_pool_t *p, } if (bytes_streamed != cl_val) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, + ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01087) "client %s given Content-Length did not match" " number of body bytes read", r->connection->peer_ip); return HTTP_BAD_REQUEST; @@ -588,7 +588,7 @@ static int spool_reqbody_cl(apr_pool_t *p, * temporary file on disk. */ if (bytes_spooled + bytes > limit) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, + ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01088) "Request body is larger than the configured " "limit of %" APR_OFF_T_FMT, limit); return HTTP_REQUEST_ENTITY_TOO_LARGE; @@ -600,7 +600,7 @@ static int spool_reqbody_cl(apr_pool_t *p, status = apr_temp_dir_get(&temp_dir, p); if (status != APR_SUCCESS) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, + ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(01089) "search for temporary directory failed"); return HTTP_INTERNAL_SERVER_ERROR; } @@ -609,7 +609,7 @@ static int spool_reqbody_cl(apr_pool_t *p, APR_FILEPATH_NATIVE, p); status = apr_file_mktemp(&tmpfile, template, 0, p); if (status != APR_SUCCESS) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, + ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(01090) "creation of temporary file in directory " "%s failed", temp_dir); return HTTP_INTERNAL_SERVER_ERROR; @@ -629,7 +629,7 @@ static int spool_reqbody_cl(apr_pool_t *p, if (apr_file_name_get(&tmpfile_name, tmpfile) != APR_SUCCESS) { tmpfile_name = "(unknown)"; } - ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, + ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(01091) "write to temporary file %s failed", tmpfile_name); return HTTP_INTERNAL_SERVER_ERROR; @@ -688,6 +688,56 @@ static int spool_reqbody_cl(apr_pool_t *p, return(pass_brigade(bucket_alloc, r, p_conn, origin, header_brigade, 1)); } +/* + * Transform buckets from one bucket allocator to another one by creating a + * transient bucket for each data bucket and let it use the data read from + * the old bucket. Metabuckets are transformed by just recreating them. + * Attention: Currently only the following bucket types are handled: + * + * All data buckets + * FLUSH + * EOS + * + * If an other bucket type is found its type is logged as a debug message + * and APR_EGENERAL is returned. + */ +static apr_status_t proxy_buckets_lifetime_transform(request_rec *r, + apr_bucket_brigade *from, apr_bucket_brigade *to) +{ + apr_bucket *e; + apr_bucket *new; + const char *data; + apr_size_t bytes; + apr_status_t rv = APR_SUCCESS; + + apr_brigade_cleanup(to); + for (e = APR_BRIGADE_FIRST(from); + e != APR_BRIGADE_SENTINEL(from); + e = APR_BUCKET_NEXT(e)) { + if (!APR_BUCKET_IS_METADATA(e)) { + apr_bucket_read(e, &data, &bytes, APR_BLOCK_READ); + new = apr_bucket_transient_create(data, bytes, r->connection->bucket_alloc); + APR_BRIGADE_INSERT_TAIL(to, new); + } + else if (APR_BUCKET_IS_FLUSH(e)) { + new = apr_bucket_flush_create(r->connection->bucket_alloc); + APR_BRIGADE_INSERT_TAIL(to, new); + } + else if (APR_BUCKET_IS_EOS(e)) { + new = apr_bucket_eos_create(r->connection->bucket_alloc); + APR_BRIGADE_INSERT_TAIL(to, new); + } + else { + ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00964) + "Unhandled bucket type of type %s in" + " proxy_buckets_lifetime_transform", e->type->name); + apr_bucket_delete(e); + rv = APR_EGENERAL; + } + } + return rv; +} + static int ap_proxy_http_request(apr_pool_t *p, request_rec *r, proxy_conn_rec *p_conn, proxy_worker *worker, @@ -781,7 +831,7 @@ int ap_proxy_http_request(apr_pool_t *p, request_rec *r, const char* hostname = apr_table_get(r->headers_in,"Host"); if (!hostname) { hostname = r->server->server_hostname; - ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, + ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(01092) "no HTTP 0.9 request (with no host line) " "on incoming request and preserve host set " "forcing hostname to be %s for uri %s", @@ -858,7 +908,7 @@ int ap_proxy_http_request(apr_pool_t *p, request_rec *r, * determine, where the original request came from. */ apr_table_mergen(r->headers_in, "X-Forwarded-For", - r->client_ip); + r->useragent_ip); /* Add X-Forwarded-Host: so that upstream knows what the * original request hostname was. @@ -993,13 +1043,13 @@ int ap_proxy_http_request(apr_pool_t *p, request_rec *r, * do not modify add_te_chunked's logic */ if (old_te_val && strcasecmp(old_te_val, "chunked") != 0) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, + ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01093) "%s Transfer-Encoding is not supported", old_te_val); return HTTP_INTERNAL_SERVER_ERROR; } if (old_cl_val && old_te_val) { - ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01094) "client %s (%s) requested Transfer-Encoding " "chunked body with Content-Length (C-L ignored)", c->peer_ip, c->remote_host ? c->remote_host: ""); @@ -1023,7 +1073,7 @@ int ap_proxy_http_request(apr_pool_t *p, request_rec *r, AP_MODE_READBYTES, APR_BLOCK_READ, MAX_MEM_SPOOL - bytes_read); if (status != APR_SUCCESS) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, + ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(01095) "prefetch request body failed to %pI (%s)" " from %s (%s)", p_conn->addr, p_conn->hostname ? p_conn->hostname: "", @@ -1045,7 +1095,7 @@ int ap_proxy_http_request(apr_pool_t *p, request_rec *r, */ status = ap_save_brigade(NULL, &input_brigade, &temp_brigade, p); if (status != APR_SUCCESS) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, + ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(01096) "processing prefetched request body failed" " to %pI (%s) from %s (%s)", p_conn->addr, p_conn->hostname ? p_conn->hostname: "", @@ -1185,7 +1235,7 @@ skip_body: if (rv != OK) { /* apr_status_t value has been logged in lower level method */ - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, + ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01097) "pass request body failed to %pI (%s) from %s (%s)", p_conn->addr, p_conn->hostname ? p_conn->hostname: "", c->peer_ip, c->remote_host ? c->remote_host: ""); @@ -1195,6 +1245,65 @@ skip_body: return OK; } +/* + * If the date is a valid RFC 850 date or asctime() date, then it + * is converted to the RFC 1123 format. + */ +static const char *date_canon(apr_pool_t *p, const char *date) +{ + apr_status_t rv; + char* ndate; + + apr_time_t time = apr_date_parse_http(date); + if (!time) { + return date; + } + + ndate = apr_palloc(p, APR_RFC822_DATE_LEN); + rv = apr_rfc822_date(ndate, time); + if (rv != APR_SUCCESS) { + return date; + } + + return ndate; +} + +static request_rec *make_fake_req(conn_rec *c, request_rec *r) +{ + apr_pool_t *pool; + request_rec *rp; + + apr_pool_create(&pool, c->pool); + + rp = apr_pcalloc(pool, sizeof(*r)); + + rp->pool = pool; + rp->status = HTTP_OK; + + rp->headers_in = apr_table_make(pool, 50); + rp->subprocess_env = apr_table_make(pool, 50); + rp->headers_out = apr_table_make(pool, 12); + rp->err_headers_out = apr_table_make(pool, 5); + rp->notes = apr_table_make(pool, 5); + + rp->server = r->server; + rp->log = r->log; + rp->proxyreq = r->proxyreq; + rp->request_time = r->request_time; + rp->connection = c; + rp->output_filters = c->output_filters; + rp->input_filters = c->input_filters; + rp->proto_output_filters = c->output_filters; + rp->proto_input_filters = c->input_filters; + rp->useragent_ip = c->peer_ip; + rp->useragent_addr = c->peer_addr; + + rp->request_config = ap_create_request_config(pool); + proxy_run_create_req(r, rp); + + return rp; +} + static void process_proxy_header(request_rec *r, proxy_dir_conf *c, const char *key, const char *value) { @@ -1215,7 +1324,7 @@ static void process_proxy_header(request_rec *r, proxy_dir_conf *c, for (i = 0; date_hdrs[i]; ++i) { if (!strcasecmp(date_hdrs[i], key)) { apr_table_add(r->headers_out, key, - ap_proxy_date_canon(r->pool, value)); + date_canon(r->pool, value)); return; } } @@ -1291,14 +1400,14 @@ static void ap_proxy_read_headers(request_rec *r, request_rec *rr, * the first line of the response. */ if (saw_headers) { - ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, + ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(01098) "Starting body due to bogus non-header " "in headers returned by %s (%s)", r->uri, r->method); *pread_len = len; return ; } else { - ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, + ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(01099) "No HTTP headers returned by %s (%s)", r->uri, r->method); return ; @@ -1306,7 +1415,7 @@ static void ap_proxy_read_headers(request_rec *r, request_rec *rr, } } /* this is the psc->badopt == bad_ignore case */ - ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, + ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(01100) "Ignoring bogus HTTP header returned by %s (%s)", r->uri, r->method); continue; @@ -1434,7 +1543,7 @@ apr_status_t ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, apr_status_t rc; rc = apr_socket_timeout_set(backend->sock, worker->s->ping_timeout); if (rc != APR_SUCCESS) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, rc, r, + ap_log_rerror(APLOG_MARK, APLOG_ERR, rc, r, APLOGNO(01101) "could not set 100-Continue timeout"); } } @@ -1444,7 +1553,7 @@ apr_status_t ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, * filter chain */ - backend->r = ap_proxy_make_fake_req(origin, r); + backend->r = make_fake_req(origin, r); /* In case anyone needs to know, this is a fake request that is really a * response. */ @@ -1463,11 +1572,11 @@ apr_status_t ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, rc = ap_proxygetline(tmp_bb, buffer, sizeof(buffer), backend->r, 0, &len); } if (len <= 0) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, rc, r, + ap_log_rerror(APLOG_MARK, APLOG_ERR, rc, r, APLOGNO(01102) "error reading status line from remote " "server %s:%d", backend->hostname, backend->port); if (APR_STATUS_IS_TIMEUP(rc)) { - ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "read timeout"); + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01103) "read timeout"); if (do_100_continue) { return ap_proxyerror(r, HTTP_SERVICE_UNAVAILABLE, "Timeout on 100-Continue"); } @@ -1487,7 +1596,7 @@ apr_status_t ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, !APR_STATUS_IS_TIMEUP(rc)) { apr_bucket *eos; - ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01104) "Closing connection to client because" " reading from backend server %s:%d failed." " Number of keepalives %i", backend->hostname, @@ -1522,7 +1631,7 @@ apr_status_t ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, return OK; } else if (!c->keepalives) { - ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01105) "NOT Closing connection to client" " although reading from backend server %s:%d" " failed.", @@ -1593,7 +1702,7 @@ apr_status_t ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, &pread_len); if (r->headers_out == NULL) { - ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, + ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(01106) "bad HTTP/%d.%d header returned by %s (%s)", major, minor, r->uri, r->method); backend->close += 1; @@ -1633,7 +1742,7 @@ apr_status_t ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, * XXX: We aught to treat such a response as uncachable */ apr_table_unset(r->headers_out, "Content-Length"); - ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01107) "server %s:%d returned Transfer-Encoding" " and Content-Length", backend->hostname, backend->port); @@ -1646,9 +1755,8 @@ apr_status_t ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, */ te = apr_table_get(r->headers_out, "Transfer-Encoding"); /* strip connection listed hop-by-hop headers from response */ - backend->close += ap_proxy_liststr(apr_table_get(r->headers_out, - "Connection"), - "close"); + backend->close += ap_find_token(p, + apr_table_get(r->headers_out, "Connection"), "close"); ap_proxy_clear_connection(p, r->headers_out); if ((buf = apr_table_get(r->headers_out, "Content-Type"))) { ap_set_content_type(r, apr_pstrdup(p, buf)); @@ -1740,7 +1848,7 @@ apr_status_t ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, * policies and maybe also add option to bail out with 502 */ else if (strcasecmp(policy, "Suppress")) { - ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, + ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, APLOGNO(01108) "undefined proxy interim response policy"); } } @@ -1754,7 +1862,7 @@ apr_status_t ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, 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, + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01109) "origin server sent 401 without " "WWW-Authenticate header"); } @@ -1878,7 +1986,7 @@ apr_status_t ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, * our backend bailed on us. Pass along a 502 error * error bucket */ - ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, + ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01110) "error reading response"); ap_proxy_backend_broke(r, bb); ap_pass_brigade(r->output_filters, bb); @@ -1893,7 +2001,7 @@ apr_status_t ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, backend->worker->s->read += readbytes; #if DEBUGGING { - ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01111) "readbytes: %#x", readbytes); } #endif @@ -1904,7 +2012,7 @@ apr_status_t ap_proxy_http_process_response(apr_pool_t * p, request_rec *r, } /* Switch the allocator lifetime of the buckets */ - ap_proxy_buckets_lifetime_transform(r, bb, pass_bb); + proxy_buckets_lifetime_transform(r, bb, pass_bb); /* found the last brigade? */ if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(pass_bb))) { @@ -2051,7 +2159,7 @@ static int proxy_http_handler(request_rec *r, proxy_worker *worker, /* is it for us? */ if (strcmp(scheme, "https") == 0) { if (!ap_proxy_ssl_enable(NULL)) { - ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01112) "HTTPS: declining URL %s (mod_ssl not configured?)", url); return DECLINED; @@ -2060,7 +2168,7 @@ static int proxy_http_handler(request_rec *r, proxy_worker *worker, proxy_function = "HTTPS"; } else if (!(strcmp(scheme, "http") == 0 || (strcmp(scheme, "ftp") == 0 && proxyname))) { - ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "HTTP: declining URL %s", + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01113) "HTTP: declining URL %s", url); return DECLINED; /* only interested in HTTP, or FTP via proxy */ } @@ -2110,7 +2218,7 @@ static int proxy_http_handler(request_rec *r, proxy_worker *worker, /* Step Two: Make the Connection */ if (ap_proxy_connect_backend(proxy_function, backend, worker, r->server)) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, + ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01114) "HTTP: failed to make connection to backend: %s", backend->hostname); status = HTTP_SERVICE_UNAVAILABLE; @@ -2141,7 +2249,7 @@ static int proxy_http_handler(request_rec *r, proxy_worker *worker, conf, uri, locurl, server_portstr)) != OK) { if ((status == HTTP_SERVICE_UNAVAILABLE) && worker->s->ping_timeout_set) { backend->close = 1; - ap_log_rerror(APLOG_MARK, APLOG_INFO, status, r, + ap_log_rerror(APLOG_MARK, APLOG_INFO, status, r, APLOGNO(01115) "HTTP: 100-Continue failed to %pI (%s)", worker->cp->addr, worker->s->hostname); retry++;