View | Details | Raw Unified | Return to bug 29744
Collapse All | Expand All

(-)httpd-2.0.52-orig/modules/proxy/proxy_connect.c (-37 / +44 lines)
Lines 83-92 Link Here
83
{
83
{
84
    apr_pool_t *p = r->pool;
84
    apr_pool_t *p = r->pool;
85
    apr_socket_t *sock;
85
    apr_socket_t *sock;
86
    conn_rec *c = r->connection;
87
    conn_rec *backconn;
88
    apr_bucket_brigade *bb = apr_brigade_create(p, c->bucket_alloc);
89
86
    apr_status_t err, rv;
90
    apr_status_t err, rv;
87
    apr_size_t i, o, nbytes;
91
    apr_size_t i, o, nbytes;
88
    char buffer[HUGE_STRING_LEN];
92
    char buffer[HUGE_STRING_LEN];
89
    apr_socket_t *client_socket = ap_get_module_config(r->connection->conn_config, &core_module);
93
    apr_socket_t *client_socket = ap_get_module_config(c->conn_config, &core_module);
90
    int failed;
94
    int failed;
91
    apr_pollfd_t *pollfd;
95
    apr_pollfd_t *pollfd;
92
    apr_int32_t pollcnt;
96
    apr_int32_t pollcnt;
Lines 211-217 Link Here
211
     * We add the NULL filter to the stack to do this...
215
     * We add the NULL filter to the stack to do this...
212
     */
216
     */
213
    r->output_filters = NULL;
217
    r->output_filters = NULL;
214
    r->connection->output_filters = NULL;
218
219
    backconn = ap_run_create_connection(c->pool, r->server, sock,
220
					c->id, c->sbh, c->bucket_alloc);
221
    if(!backconn) {
222
	/* peer reset */
223
	ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
224
		     "proxy: an error occurred creating a new connection "
225
		     "to %pI (%s)", connect_addr, connectname);
226
	apr_socket_close(sock);
227
	return HTTP_INTERNAL_SERVER_ERROR;
228
    }
229
    ap_proxy_ssl_disable(backconn);
230
    ap_run_pre_connection(backconn, sock);
231
232
    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
233
		 "proxy: connection complete to %pI (%s)",
234
		 connect_addr, connectname);
215
235
216
236
217
    /* If we are connecting through a remote proxy, we need to pass
237
    /* If we are connecting through a remote proxy, we need to pass
Lines 222-233 Link Here
222
	 */
242
	 */
223
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
243
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
224
		     "proxy: CONNECT: sending the CONNECT request to the remote proxy");
244
		     "proxy: CONNECT: sending the CONNECT request to the remote proxy");
225
        nbytes = apr_snprintf(buffer, sizeof(buffer),
245
246
	ap_fprintf(backconn->output_filters, bb,
226
			      "CONNECT %s HTTP/1.0" CRLF, r->uri);
247
			      "CONNECT %s HTTP/1.0" CRLF, r->uri);
227
        apr_send(sock, buffer, &nbytes);
248
	ap_fprintf(backconn->output_filters, bb,
228
        nbytes = apr_snprintf(buffer, sizeof(buffer),
249
		   "Proxy-agent: %s" CRLF CRLF, ap_get_server_version());
229
			      "Proxy-agent: %s" CRLF CRLF, ap_get_server_version());
250
	ap_fflush(backconn->output_filters, bb);
230
        apr_send(sock, buffer, &nbytes);
231
    }
251
    }
232
    else {
252
    else {
233
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
253
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
Lines 235-245 Link Here
235
        nbytes = apr_snprintf(buffer, sizeof(buffer),
255
        nbytes = apr_snprintf(buffer, sizeof(buffer),
236
			      "HTTP/1.0 200 Connection Established" CRLF);
256
			      "HTTP/1.0 200 Connection Established" CRLF);
237
        ap_xlate_proto_to_ascii(buffer, nbytes);
257
        ap_xlate_proto_to_ascii(buffer, nbytes);
238
        apr_send(client_socket, buffer, &nbytes);
258
        ap_fwrite(c->output_filters, bb, buffer, nbytes);
239
        nbytes = apr_snprintf(buffer, sizeof(buffer),
259
        nbytes = apr_snprintf(buffer, sizeof(buffer),
240
			      "Proxy-agent: %s" CRLF CRLF, ap_get_server_version());
260
			      "Proxy-agent: %s" CRLF CRLF, ap_get_server_version());
241
        ap_xlate_proto_to_ascii(buffer, nbytes);
261
        ap_xlate_proto_to_ascii(buffer, nbytes);
242
        apr_send(client_socket, buffer, &nbytes);
262
        ap_fwrite(c->output_filters, bb, buffer, nbytes);
263
	ap_fflush(c->output_filters, bb);
243
#if 0
264
#if 0
244
        /* This is safer code, but it doesn't work yet.  I'm leaving it 
265
        /* This is safer code, but it doesn't work yet.  I'm leaving it 
245
         * here so that I can fix it later.
266
         * here so that I can fix it later.
Lines 293-315 Link Here
293
/*		ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
314
/*		ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
294
                             "proxy: CONNECT: sock was set");*/
315
                             "proxy: CONNECT: sock was set");*/
295
                nbytes = sizeof(buffer);
316
                nbytes = sizeof(buffer);
296
                if (apr_recv(sock, buffer, &nbytes) == APR_SUCCESS) {
317
		apr_brigade_cleanup(bb);
297
                    o = 0;
318
                if (ap_get_brigade(backconn->input_filters, bb,
298
                    i = nbytes;
319
				   AP_MODE_READBYTES, APR_NONBLOCK_READ,
299
                    while(i > 0)
320
				   nbytes) == APR_SUCCESS) {
300
                    {
321
		    if (ap_pass_brigade(c->output_filters, bb) != APR_SUCCESS)
301
                        nbytes = i;
322
			break;
302
    /* This is just plain wrong.  No module should ever write directly
323
		    ap_fflush(c->output_filters, bb);
303
     * to the client.  For now, this works, but this is high on my list of
304
     * things to fix.  The correct line is:
305
     * if ((nbytes = ap_rwrite(buffer + o, nbytes, r)) < 0)
306
     * rbb
307
     */
308
                        if (apr_send(client_socket, buffer + o, &nbytes) != APR_SUCCESS)
309
			    break;
310
                        o += nbytes;
311
                        i -= nbytes;
312
                    }
313
                }
324
                }
314
                else
325
                else
315
                    break;
326
                    break;
Lines 323-339 Link Here
323
/*		ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
334
/*		ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
324
                             "proxy: CONNECT: client was set");*/
335
                             "proxy: CONNECT: client was set");*/
325
                nbytes = sizeof(buffer);
336
                nbytes = sizeof(buffer);
326
                if (apr_recv(client_socket, buffer, &nbytes) == APR_SUCCESS) {
337
		apr_brigade_cleanup(bb);
327
                    o = 0;
338
                if (ap_get_brigade(c->input_filters, bb, AP_MODE_READBYTES,
328
                    i = nbytes;
339
				   APR_NONBLOCK_READ, nbytes) == APR_SUCCESS) {
329
                    while(i > 0)
340
		    if (ap_pass_brigade(backconn->output_filters, bb)
330
                    {
341
			!= APR_SUCCESS)
331
			nbytes = i;
342
			break;
332
			if (apr_send(sock, buffer + o, &nbytes) != APR_SUCCESS)
343
		    ap_fflush(backconn->output_filters, bb);
333
			    break;
334
                        o += nbytes;
335
                        i -= nbytes;
336
                    }
337
                }
344
                }
338
                else
345
                else
339
                    break;
346
                    break;

Return to bug 29744