diff options
author | Ryan Bloom <rbb@apache.org> | 2000-11-16 02:57:46 +0100 |
---|---|---|
committer | Ryan Bloom <rbb@apache.org> | 2000-11-16 02:57:46 +0100 |
commit | 274c566f2b8ac5776e18ebbdecfe2b5b6388f8f9 (patch) | |
tree | 41e8d9884ef91e905f05730bdd52dee4302344f6 /modules | |
parent | use apr_size_t (diff) | |
download | apache2-274c566f2b8ac5776e18ebbdecfe2b5b6388f8f9.tar.xz apache2-274c566f2b8ac5776e18ebbdecfe2b5b6388f8f9.zip |
Make the proxy work with filters. We are still using BUFF for the
back-end communication, but BUFF has been removed from the communication
with the client. The headers are not working correctly yet, but we are
making progress. The most important part of this commit is that we are
able to actually filter data coming from the proxy.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@86978 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'modules')
-rw-r--r-- | modules/proxy/mod_proxy.h | 2 | ||||
-rw-r--r-- | modules/proxy/proxy_ftp.c | 2 | ||||
-rw-r--r-- | modules/proxy/proxy_http.c | 46 | ||||
-rw-r--r-- | modules/proxy/proxy_util.c | 27 |
4 files changed, 49 insertions, 28 deletions
diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h index 951d9d8eb9..5fde7e2bd0 100644 --- a/modules/proxy/mod_proxy.h +++ b/modules/proxy/mod_proxy.h @@ -256,7 +256,7 @@ char *ap_proxy_canon_netloc(apr_pool_t *p, char **const urlp, char **userp, char **passwordp, char **hostp, int *port); const char *ap_proxy_date_canon(apr_pool_t *p, const char *x); apr_table_t *ap_proxy_read_headers(request_rec *r, char *buffer, int size, BUFF *f); -long int ap_proxy_send_fb(proxy_completion *, apr_socket_t *f, request_rec *r, ap_cache_el *c); +long int ap_proxy_send_fb(proxy_completion *, BUFF *f, request_rec *r, ap_cache_el *c); void ap_proxy_send_headers(request_rec *r, const char *respline, apr_table_t *hdrs); int ap_proxy_liststr(const char *list, const char *val); void ap_proxy_hash(const char *it, char *val, int ndepth, int nlength); diff --git a/modules/proxy/proxy_ftp.c b/modules/proxy/proxy_ftp.c index dc6cd9083a..c943702ac9 100644 --- a/modules/proxy/proxy_ftp.c +++ b/modules/proxy/proxy_ftp.c @@ -1206,7 +1206,7 @@ int ap_proxy_ftp_handler(request_rec *r, ap_cache_el *c, char *url) /* send body */ if (!r->header_only) { if (parms[0] != 'd') { - ap_proxy_send_fb(NULL, dsock, r, c); + ap_proxy_send_fb(NULL, data, r, c); } else send_dir(data, r, c, cwd); diff --git a/modules/proxy/proxy_http.c b/modules/proxy/proxy_http.c index a7493cd2eb..c6a4481b23 100644 --- a/modules/proxy/proxy_http.c +++ b/modules/proxy/proxy_http.c @@ -191,6 +191,8 @@ int ap_proxy_http_handler(request_rec *r, ap_cache_el *c, char *url, char *datestr, *clen; apr_ssize_t cntr; apr_file_t *cachefp = NULL; + char *buf; + int rbb; void *sconf = r->server->module_config; proxy_server_conf *conf = @@ -277,12 +279,20 @@ int ap_proxy_http_handler(request_rec *r, ap_cache_el *c, char *url, f = ap_bcreate(p, B_RDWR); ap_bpush_socket(f, sock); - ap_bvputs(f, r->method, " ", proxyhost ? url : urlptr, " HTTP/1.0" CRLF, - NULL); - if (destportstr != NULL && destport != DEFAULT_HTTP_PORT) - ap_bvputs(f, "Host: ", desthost, ":", destportstr, CRLF, NULL); - else - ap_bvputs(f, "Host: ", desthost, CRLF, NULL); + buf = apr_pstrcat(r->pool, r->method, " ", proxyhost ? url : urlptr, + " HTTP/1.0" CRLF, NULL); + rbb = strlen(buf); + apr_send(sock, buf, &rbb); + if (destportstr != NULL && destport != DEFAULT_HTTP_PORT) { + buf = apr_pstrcat(r->pool, "Host: ", desthost, ":", destportstr, CRLF, NULL); + rbb = strlen(buf); + apr_send(sock, buf, &rbb); + } + else { + buf = apr_pstrcat(r->pool, "Host: ", desthost, CRLF, NULL); + rbb = strlen(buf); + apr_send(sock, buf, &rbb); + } if (conf->viaopt == via_block) { /* Block all outgoing Via: headers */ @@ -322,17 +332,27 @@ int ap_proxy_http_handler(request_rec *r, ap_cache_el *c, char *url, */ || !strcasecmp(reqhdrs[i].key, "Proxy-Authorization")) continue; - ap_bvputs(f, reqhdrs[i].key, ": ", reqhdrs[i].val, CRLF, NULL); + buf = apr_pstrcat(r->pool, reqhdrs[i].key, ": ", reqhdrs[i].val, CRLF, NULL); + rbb = strlen(buf); + apr_send(sock, buf, &rbb); + } - ap_bputs(CRLF, f); + rbb = strlen(CRLF); + apr_send(sock, CRLF, &rbb); /* send the request data, if any. */ if (ap_should_client_block(r)) { - while ((i = ap_get_client_block(r, buffer, sizeof buffer)) > 0) - ap_bwrite(f, buffer, i, &cntr); + while ((i = ap_get_client_block(r, buffer, sizeof buffer)) > 0) { + cntr = i; + apr_send(sock, buffer, &cntr); + } } +#if 0 /* This doesn't make any sense until we convert the raw socket calls + * to filters. + */ ap_bflush(f); +#endif len = ap_bgets(buffer, sizeof buffer - 1, f); if (len == -1) { @@ -440,8 +460,10 @@ int ap_proxy_http_handler(request_rec *r, ap_cache_el *c, char *url, ap_cache_el_data(c, &cachefp); /* write status line */ +#if 0 if (!r->assbackwards) ap_rvputs(r, "HTTP/1.0 ", r->status_line, CRLF, NULL); +#endif if (cachefp && apr_puts(apr_pstrcat(r->pool, "HTTP/1.0 ", r->status_line, CRLF, NULL), cachefp) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, @@ -453,8 +475,10 @@ int ap_proxy_http_handler(request_rec *r, ap_cache_el *c, char *url, /* send headers */ ap_cache_el_header_walk(c, ap_proxy_send_hdr_line, r, NULL); +#if 0 if (!r->assbackwards) ap_rputs(CRLF, r); +#endif /* We don't set byte count this way anymore. I think this can be removed * cleanly now. @@ -488,7 +512,7 @@ int ap_proxy_http_handler(request_rec *r, ap_cache_el *c, char *url, proxy_completion pc; pc.content_length = content_length; pc.cache_completion = conf->cache_completion; - ap_proxy_send_fb(&pc, sock, r, c); + ap_proxy_send_fb(&pc, f, r, c); } ap_bclose(f); diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index 6338ca92be..8466251605 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -490,7 +490,7 @@ apr_table_t *ap_proxy_read_headers(request_rec *r, char *buffer, int size, BUFF return resp_hdrs; } -long int ap_proxy_send_fb(proxy_completion *completion, apr_socket_t *f, request_rec *r, ap_cache_el *c) +long int ap_proxy_send_fb(proxy_completion *completion, BUFF *f, request_rec *r, ap_cache_el *c) { int ok; char buf[IOBUFSIZE]; @@ -544,8 +544,7 @@ long int ap_proxy_send_fb(proxy_completion *completion, apr_socket_t *f, request */ for (ok = 1; ok; cntr = 0) { /* Read block from server */ - cntr = IOBUFSIZE; - if (apr_recv(f, buf, &cntr) != APR_SUCCESS && !cntr) + if (ap_bread(f, buf, IOBUFSIZE, &cntr) != APR_SUCCESS && !cntr) { if (c != NULL) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, @@ -573,8 +572,7 @@ long int ap_proxy_send_fb(proxy_completion *completion, apr_socket_t *f, request /* Write the block to the client, detect aborted transfers */ while (!con->aborted && in_buffer > 0) { - cntr = in_buffer; - if (apr_send(con->client_socket, &buf[o], &cntr) != APR_SUCCESS) { + if ((cntr = ap_rwrite(&buf[o], in_buffer, r))) { if (completion) { /* when a send failure occurs, we need to decide * whether to continue loading and caching the @@ -595,11 +593,8 @@ long int ap_proxy_send_fb(proxy_completion *completion, apr_socket_t *f, request } /* while client alive and more data to send */ } /* loop and ap_bread while "ok" */ -/* Remove this stuff, because flushing a socket doesn't make a lot of sense - * currently. if (!con->aborted) - ap_bflush(con->client); -*/ + ap_rflush(r); return total_bytes_rcvd; } @@ -1235,12 +1230,17 @@ static struct per_thread_data *get_per_thread_data(void) return NULL; } +/* This function is completely bogus. This should become a part of the + * cache filter when it is finished. RBB + */ int ap_proxy_cache_send(request_rec *r, ap_cache_el *c) { apr_file_t *cachefp = NULL; apr_socket_t *fp = r->connection->client_socket; char buffer[500]; apr_size_t len; + apr_off_t offset = 0; + apr_finfo_t finfo; ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, NULL, "Sending cache file for %s", c->name); @@ -1250,18 +1250,15 @@ int ap_proxy_cache_send(request_rec *r, ap_cache_el *c) if(apr_fgets(buffer, sizeof(buffer), cachefp)) { len = strlen(buffer); apr_send(fp, buffer, &len); + offset +=len; } /* send headers */ ap_cache_el_header_walk(c, ap_proxy_send_hdr_line, r, NULL); len = 2; apr_send(fp, CRLF, &len); /* send data */ - /* XXX I changed the ap_proxy_send_fb call to use fp instead of cachefp. - * this compiles cleanly, but it is probably the completely wrong - * solution. We need to go through the proxy code, and remove all - * of the BUFF's. rbb - */ - if(!r->header_only && !ap_proxy_send_fb(0, fp, r, NULL)) + apr_getfileinfo(&finfo, cachefp); + if(!r->header_only && ap_send_fd(cachefp, r, offset, finfo.size, &len)) return HTTP_INTERNAL_SERVER_ERROR; return OK; } |