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);
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 =
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 */
*/
|| !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) {
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,
/* 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.
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);
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];
*/
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,
/* 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
} /* 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;
}
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);
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;
}