Lines 78-87
Link Here
|
78 |
{ |
78 |
{ |
79 |
apr_pool_t *p = r->pool; |
79 |
apr_pool_t *p = r->pool; |
80 |
apr_socket_t *sock; |
80 |
apr_socket_t *sock; |
|
|
81 |
conn_rec *c = r->connection; |
82 |
conn_rec *backconn; |
83 |
apr_bucket_brigade *bb = apr_brigade_create(p, c->bucket_alloc); |
84 |
|
81 |
apr_status_t err, rv; |
85 |
apr_status_t err, rv; |
82 |
apr_size_t i, o, nbytes; |
86 |
apr_size_t i, o, nbytes; |
83 |
char buffer[HUGE_STRING_LEN]; |
87 |
char buffer[HUGE_STRING_LEN]; |
84 |
apr_socket_t *client_socket = ap_get_module_config(r->connection->conn_config, &core_module); |
88 |
apr_socket_t *client_socket = ap_get_module_config(c->conn_config, &core_module); |
85 |
int failed; |
89 |
int failed; |
86 |
apr_pollset_t *pollset; |
90 |
apr_pollset_t *pollset; |
87 |
apr_pollfd_t pollfd; |
91 |
apr_pollfd_t pollfd; |
Lines 208-214
Link Here
|
208 |
* We add the NULL filter to the stack to do this... |
212 |
* We add the NULL filter to the stack to do this... |
209 |
*/ |
213 |
*/ |
210 |
r->output_filters = NULL; |
214 |
r->output_filters = NULL; |
211 |
r->connection->output_filters = NULL; |
215 |
|
|
|
216 |
backconn = ap_run_create_connection(c->pool, r->server, sock, |
217 |
c->id, c->sbh, c->bucket_alloc); |
218 |
if(!backconn) { |
219 |
/* peer reset */ |
220 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, |
221 |
"proxy: an error occurred creating a new connection " |
222 |
"to %pI (%s)", connect_addr, connectname); |
223 |
apr_socket_close(sock); |
224 |
return HTTP_INTERNAL_SERVER_ERROR; |
225 |
} |
226 |
ap_proxy_ssl_disable(backconn); |
227 |
ap_run_pre_connection(backconn, sock); |
228 |
|
229 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, |
230 |
"proxy: connection complete to %pI (%s)", |
231 |
connect_addr, connectname); |
212 |
|
232 |
|
213 |
|
233 |
|
214 |
/* If we are connecting through a remote proxy, we need to pass |
234 |
/* If we are connecting through a remote proxy, we need to pass |
Lines 219-230
Link Here
|
219 |
*/ |
239 |
*/ |
220 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, |
240 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, |
221 |
"proxy: CONNECT: sending the CONNECT request to the remote proxy"); |
241 |
"proxy: CONNECT: sending the CONNECT request to the remote proxy"); |
222 |
nbytes = apr_snprintf(buffer, sizeof(buffer), |
242 |
ap_fprintf(backconn->output_filters, bb, |
223 |
"CONNECT %s HTTP/1.0" CRLF, r->uri); |
243 |
"CONNECT %s HTTP/1.0" CRLF, r->uri); |
224 |
apr_socket_send(sock, buffer, &nbytes); |
244 |
ap_fprintf(backconn->output_filters, bb, |
225 |
nbytes = apr_snprintf(buffer, sizeof(buffer), |
245 |
"Proxy-agent: %s" CRLF CRLF, ap_get_server_version()); |
226 |
"Proxy-agent: %s" CRLF CRLF, ap_get_server_version()); |
246 |
ap_fflush(backconn->output_filters, bb); |
227 |
apr_socket_send(sock, buffer, &nbytes); |
|
|
228 |
} |
247 |
} |
229 |
else { |
248 |
else { |
230 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, |
249 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, |
Lines 232-242
Link Here
|
232 |
nbytes = apr_snprintf(buffer, sizeof(buffer), |
251 |
nbytes = apr_snprintf(buffer, sizeof(buffer), |
233 |
"HTTP/1.0 200 Connection Established" CRLF); |
252 |
"HTTP/1.0 200 Connection Established" CRLF); |
234 |
ap_xlate_proto_to_ascii(buffer, nbytes); |
253 |
ap_xlate_proto_to_ascii(buffer, nbytes); |
235 |
apr_socket_send(client_socket, buffer, &nbytes); |
254 |
ap_fwrite(c->output_filters, bb, buffer, nbytes); |
236 |
nbytes = apr_snprintf(buffer, sizeof(buffer), |
255 |
nbytes = apr_snprintf(buffer, sizeof(buffer), |
237 |
"Proxy-agent: %s" CRLF CRLF, ap_get_server_version()); |
256 |
"Proxy-agent: %s" CRLF CRLF, ap_get_server_version()); |
238 |
ap_xlate_proto_to_ascii(buffer, nbytes); |
257 |
ap_xlate_proto_to_ascii(buffer, nbytes); |
239 |
apr_socket_send(client_socket, buffer, &nbytes); |
258 |
ap_fwrite(c->output_filters, bb, buffer, nbytes); |
|
|
259 |
ap_fflush(c->output_filters, bb); |
240 |
#if 0 |
260 |
#if 0 |
241 |
/* This is safer code, but it doesn't work yet. I'm leaving it |
261 |
/* This is safer code, but it doesn't work yet. I'm leaving it |
242 |
* here so that I can fix it later. |
262 |
* here so that I can fix it later. |
Lines 301-331
Link Here
|
301 |
"proxy: CONNECT: sock was set"); |
321 |
"proxy: CONNECT: sock was set"); |
302 |
#endif |
322 |
#endif |
303 |
nbytes = sizeof(buffer); |
323 |
nbytes = sizeof(buffer); |
304 |
rv = apr_socket_recv(sock, buffer, &nbytes); |
324 |
apr_brigade_cleanup(bb); |
305 |
if (rv == APR_SUCCESS) { |
325 |
rv = ap_get_brigade(backconn->input_filters, bb, |
306 |
o = 0; |
326 |
AP_MODE_READBYTES, APR_NONBLOCK_READ, |
307 |
i = nbytes; |
327 |
nbytes); |
308 |
while(i > 0) |
328 |
if (rv != APR_SUCCESS) { |
309 |
{ |
329 |
#ifdef DEBUGGING |
310 |
nbytes = i; |
330 |
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, rv, r, |
311 |
/* This is just plain wrong. No module should ever write directly |
331 |
"proxy: CONNECT: error ap_get_brigade"); |
312 |
* to the client. For now, this works, but this is high on my list of |
332 |
#endif |
313 |
* things to fix. The correct line is: |
333 |
break; |
314 |
* if ((nbytes = ap_rwrite(buffer + o, nbytes, r)) < 0) |
|
|
315 |
* rbb |
316 |
*/ |
317 |
rv = apr_socket_send(client_socket, buffer + o, &nbytes); |
318 |
if (rv != APR_SUCCESS) |
319 |
break; |
320 |
o += nbytes; |
321 |
i -= nbytes; |
322 |
} |
323 |
} |
334 |
} |
324 |
else |
335 |
rv = ap_pass_brigade(c->output_filters, bb); |
325 |
break; |
336 |
if (rv != APR_SUCCESS) { |
|
|
337 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, |
338 |
"proxy: CONNECT: error ap_pass_brigade"); |
339 |
break; |
340 |
} |
341 |
ap_fflush(c->output_filters, bb); |
326 |
} |
342 |
} |
327 |
else if ((pollevent & APR_POLLERR) || (pollevent & APR_POLLHUP)) |
343 |
if ((pollevent & APR_POLLERR) || (pollevent & APR_POLLHUP)) { |
|
|
344 |
rv = APR_EPIPE; |
345 |
ap_log_rerror(APLOG_MARK, APLOG_NOTICE, rv, r, |
346 |
"proxy: CONNECT: err/hup on backconn"); |
328 |
break; |
347 |
break; |
|
|
348 |
} |
329 |
} |
349 |
} |
330 |
else if (cur->desc.s == client_socket) { |
350 |
else if (cur->desc.s == client_socket) { |
331 |
pollevent = cur->rtnevents; |
351 |
pollevent = cur->rtnevents; |
Lines 335-366
Link Here
|
335 |
"proxy: CONNECT: client was set"); |
355 |
"proxy: CONNECT: client was set"); |
336 |
#endif |
356 |
#endif |
337 |
nbytes = sizeof(buffer); |
357 |
nbytes = sizeof(buffer); |
338 |
rv = apr_socket_recv(client_socket, buffer, &nbytes); |
358 |
apr_brigade_cleanup(bb); |
|
|
359 |
rv = ap_get_brigade(c->input_filters, bb, |
360 |
AP_MODE_READBYTES, APR_NONBLOCK_READ, |
361 |
nbytes); |
339 |
if (rv == APR_SUCCESS) { |
362 |
if (rv == APR_SUCCESS) { |
340 |
o = 0; |
|
|
341 |
i = nbytes; |
342 |
#ifdef DEBUGGING |
363 |
#ifdef DEBUGGING |
343 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, |
364 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, |
344 |
"proxy: CONNECT: read %d from client", i); |
365 |
"proxy: CONNECT: read %d from client", i); |
345 |
#endif |
366 |
#endif |
346 |
while(i > 0) |
367 |
rv = ap_pass_brigade(backconn->output_filters, bb); |
347 |
{ |
368 |
if (rv != APR_SUCCESS) { |
348 |
nbytes = i; |
369 |
ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, |
349 |
rv = apr_socket_send(sock, buffer + o, &nbytes); |
370 |
"proxy: CONNECT: error ap_pass_brigade()"); |
350 |
if (rv != APR_SUCCESS) |
371 |
break; |
351 |
break; |
372 |
} |
352 |
o += nbytes; |
373 |
ap_fflush(backconn->output_filters, bb); |
353 |
i -= nbytes; |
374 |
} |
354 |
} |
|
|
355 |
} |
356 |
else |
375 |
else |
357 |
break; |
376 |
break; |
358 |
} |
377 |
} |
359 |
else if ((pollevent & APR_POLLERR) || (pollevent & APR_POLLHUP)) |
378 |
if ((pollevent & APR_POLLERR) || (pollevent & APR_POLLHUP)) { |
|
|
379 |
rv = APR_EPIPE; |
380 |
ap_log_rerror(APLOG_MARK, APLOG_NOTICE, rv, r, |
381 |
"proxy: CONNECT: err/hup on client sock"); |
360 |
break; |
382 |
break; |
|
|
383 |
} |
361 |
} |
384 |
} |
362 |
else |
385 |
else { |
|
|
386 |
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, |
387 |
"proxy: CONNECT: unknown socket in pollset"); |
363 |
break; |
388 |
break; |
|
|
389 |
} |
364 |
} |
390 |
} |
365 |
if (rv != APR_SUCCESS) { |
391 |
if (rv != APR_SUCCESS) { |
366 |
break; |
392 |
break; |
Lines 376-382
Link Here
|
376 |
* Close the socket and clean up |
402 |
* Close the socket and clean up |
377 |
*/ |
403 |
*/ |
378 |
|
404 |
|
379 |
apr_socket_close(sock); |
405 |
ap_lingering_close(backconn); |
380 |
|
406 |
|
381 |
return OK; |
407 |
return OK; |
382 |
} |
408 |
} |