1
0
mirror of https://github.com/apache/httpd.git synced 2025-08-08 15:02:10 +03:00

* Let mod_proxy_wstunnel and mod_proxy_connect use ap_proxy_transfer_between_connections

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1728481 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ruediger Pluem
2016-02-04 13:57:14 +00:00
parent fbf68524d3
commit b70e849980
2 changed files with 27 additions and 125 deletions

View File

@@ -143,55 +143,6 @@ static int proxy_connect_canon(request_rec *r, char *url)
return OK; return OK;
} }
/* read available data (in blocks of CONN_BLKSZ) from c_i and copy to c_o */
static int proxy_connect_transfer(request_rec *r, conn_rec *c_i, conn_rec *c_o,
apr_bucket_brigade *bb_i,
apr_bucket_brigade *bb_o, char *name)
{
int rv;
#ifdef DEBUGGING
apr_off_t len;
#endif
do {
apr_brigade_cleanup(bb_i);
rv = ap_get_brigade(c_i->input_filters, bb_i, AP_MODE_READBYTES,
APR_NONBLOCK_READ, CONN_BLKSZ);
if (rv == APR_SUCCESS) {
if (c_o->aborted)
return APR_EPIPE;
if (APR_BRIGADE_EMPTY(bb_i))
break;
#ifdef DEBUGGING
len = -1;
apr_brigade_length(bb_i, 0, &len);
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01016)
"read %" APR_OFF_T_FMT
" bytes from %s", len, name);
#endif
ap_proxy_buckets_lifetime_transform(r, bb_i, bb_o);
rv = ap_pass_brigade(c_o->output_filters, bb_o);
if (rv == APR_SUCCESS) {
ap_fflush(c_o->output_filters, bb_o);
}
else {
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01017)
"error on %s - ap_pass_brigade",
name);
}
} else if (!APR_STATUS_IS_EAGAIN(rv)) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, rv, r, APLOGNO(01018)
"error on %s - ap_get_brigade",
name);
}
} while (rv == APR_SUCCESS);
if (APR_STATUS_IS_EAGAIN(rv)) {
rv = APR_SUCCESS;
}
return rv;
}
/* CONNECT handler */ /* CONNECT handler */
static int proxy_connect_handler(request_rec *r, proxy_worker *worker, static int proxy_connect_handler(request_rec *r, proxy_worker *worker,
proxy_server_conf *conf, proxy_server_conf *conf,
@@ -445,8 +396,11 @@ static int proxy_connect_handler(request_rec *r, proxy_worker *worker,
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01025) ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01025)
"sock was readable"); "sock was readable");
#endif #endif
done |= proxy_connect_transfer(r, backconn, c, bb_back, done |= ap_proxy_transfer_between_connections(r, backconn,
bb_front, "sock") c, bb_back,
bb_front,
"sock", NULL,
CONN_BLKSZ, 1)
!= APR_SUCCESS; != APR_SUCCESS;
} }
else if (pollevent & APR_POLLERR) { else if (pollevent & APR_POLLERR) {
@@ -463,8 +417,13 @@ static int proxy_connect_handler(request_rec *r, proxy_worker *worker,
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01027) ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01027)
"client was readable"); "client was readable");
#endif #endif
done |= proxy_connect_transfer(r, c, backconn, bb_front, done |= ap_proxy_transfer_between_connections(r, c,
bb_back, "client") backconn,
bb_front,
bb_back,
"client",
NULL,
CONN_BLKSZ, 1)
!= APR_SUCCESS; != APR_SUCCESS;
} }
else if (pollevent & APR_POLLERR) { else if (pollevent & APR_POLLERR) {

View File

@@ -37,11 +37,6 @@ typedef struct ws_baton_t {
char *scheme; /* required to release the proxy connection */ char *scheme; /* required to release the proxy connection */
} ws_baton_t; } ws_baton_t;
static apr_status_t proxy_wstunnel_transfer(request_rec *r,
conn_rec *c_i, conn_rec *c_o,
apr_bucket_brigade *bb_i,
apr_bucket_brigade *bb_o,
const char *name, int *sent);
static void proxy_wstunnel_callback(void *b); static void proxy_wstunnel_callback(void *b);
static int proxy_wstunnel_pump(ws_baton_t *baton, apr_time_t timeout, int try_async) { static int proxy_wstunnel_pump(ws_baton_t *baton, apr_time_t timeout, int try_async) {
@@ -92,8 +87,11 @@ static int proxy_wstunnel_pump(ws_baton_t *baton, apr_time_t timeout, int try_as
if (pollevent & (APR_POLLIN | APR_POLLHUP)) { if (pollevent & (APR_POLLIN | APR_POLLHUP)) {
ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, APLOGNO(02446) ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, APLOGNO(02446)
"sock was readable"); "sock was readable");
done |= proxy_wstunnel_transfer(r, backconn, c, bb_i, bb_o, done |= ap_proxy_transfer_between_connections(r, backconn,
"sock", NULL) c, bb_i, bb_o,
"sock", NULL,
AP_IOBUFSIZE,
0)
!= APR_SUCCESS; != APR_SUCCESS;
} }
else if (pollevent & APR_POLLERR) { else if (pollevent & APR_POLLERR) {
@@ -113,8 +111,12 @@ static int proxy_wstunnel_pump(ws_baton_t *baton, apr_time_t timeout, int try_as
if (pollevent & (APR_POLLIN | APR_POLLHUP)) { if (pollevent & (APR_POLLIN | APR_POLLHUP)) {
ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, APLOGNO(02448) ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, APLOGNO(02448)
"client was readable"); "client was readable");
done |= proxy_wstunnel_transfer(r, c, backconn, bb_o, bb_i, done |= ap_proxy_transfer_between_connections(r, c, backconn,
"client", &replied) bb_o, bb_i,
"client",
&replied,
AP_IOBUFSIZE,
0)
!= APR_SUCCESS; != APR_SUCCESS;
} }
else if (pollevent & APR_POLLERR) { else if (pollevent & APR_POLLERR) {
@@ -272,65 +274,6 @@ static int proxy_wstunnel_canon(request_rec *r, char *url)
return OK; return OK;
} }
static apr_status_t proxy_wstunnel_transfer(request_rec *r,
conn_rec *c_i, conn_rec *c_o,
apr_bucket_brigade *bb_i,
apr_bucket_brigade *bb_o,
const char *name, int *sent)
{
apr_status_t rv;
#ifdef DEBUGGING
apr_off_t len;
#endif
do {
apr_brigade_cleanup(bb_i);
rv = ap_get_brigade(c_i->input_filters, bb_i, AP_MODE_READBYTES,
APR_NONBLOCK_READ, AP_IOBUFSIZE);
if (rv == APR_SUCCESS) {
if (c_o->aborted) {
return APR_EPIPE;
}
if (APR_BRIGADE_EMPTY(bb_i)) {
break;
}
#ifdef DEBUGGING
len = -1;
apr_brigade_length(bb_i, 0, &len);
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02440)
"read %" APR_OFF_T_FMT
" bytes from %s", len, name);
#endif
if (sent) {
*sent = 1;
}
ap_proxy_buckets_lifetime_transform(r, bb_i, bb_o);
rv = ap_pass_brigade(c_o->output_filters, bb_o);
if (rv == APR_SUCCESS) {
ap_fflush(c_o->output_filters, bb_o);
}
else {
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(02441)
"error on %s - ap_pass_brigade",
name);
}
} else if (!APR_STATUS_IS_EAGAIN(rv) && !APR_STATUS_IS_EOF(rv)) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, rv, r, APLOGNO(02442)
"error on %s - ap_get_brigade",
name);
}
} while (rv == APR_SUCCESS);
ap_log_rerror(APLOG_MARK, APLOG_TRACE2, rv, r, "wstunnel_transfer complete");
if (APR_STATUS_IS_EAGAIN(rv)) {
rv = APR_SUCCESS;
}
return rv;
}
/* /*
* process the request and write the response. * process the request and write the response.
*/ */