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

(-)modules/proxy/mod_proxy_wstunnel.c (+51 lines)
Lines 312-317 Link Here
312
    return rv;
312
    return rv;
313
}
313
}
314
314
315
/* Discard any data that has already been read from the socket and are
316
 * lingering around in the input filter chain
317
 */
318
static apr_status_t proxy_wstunnel_strip_extra_data(request_rec *r)
319
{
320
    apr_bucket_brigade *bb;
321
    conn_rec *c = r->connection;
322
    apr_status_t rv;
323
    apr_off_t len;
324
325
    bb = apr_brigade_create(r->pool, c->bucket_alloc);
326
    rv = ap_get_brigade(c->input_filters, bb, AP_MODE_READBYTES,
327
                        APR_NONBLOCK_READ, APR_BUCKET_BUFF_SIZE);
328
    if (APR_STATUS_IS_EAGAIN(rv)) {
329
	ap_log_rerror(APLOG_MARK, APLOG_TRACE2, rv, r,
330
		      "client didn't send extra data after "
331
		      "WebSocket request headers");
332
	return OK;
333
    }
334
    if (rv != APR_SUCCESS) {
335
	ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
336
		      "unexpected error when checking for extra data "
337
		      "after WebSocket request headers");
338
	return rv;
339
    }
340
341
    rv = apr_brigade_length(bb, 0, &len);
342
    ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r,
343
		  "removed %s bytes extra data received from client "
344
		  "after WebSocket request headers",
345
		  apr_off_t_toa(r->pool, len));
346
347
    return APR_SUCCESS;
348
}
349
315
/*
350
/*
316
 * process the request and write the response.
351
 * process the request and write the response.
317
 */
352
 */
Lines 476-481 Link Here
476
    uri = apr_palloc(p, sizeof(*uri));
511
    uri = apr_palloc(p, sizeof(*uri));
477
    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02451) "serving URL %s", url);
512
    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02451) "serving URL %s", url);
478
513
514
    /* Some clients send extra data (e.g. an additional CRLF) after the
515
     * request headers and before the backend server has sent the
516
     * "101 Switching Protocols" response. If this data is not meant to
517
     * be consumend after switching to the websocket protocol, this is a HTTP
518
     * protocol violation. If proxy-wstunnel-strip-extra-data is set, this
519
     * extra data is stripped, i.e. not forwarded to the backend server.
520
     * This can help with backend servers that get confused if the additional
521
     * CRLF is forwarded later from within proxy_wstunnel_request().
522
     */
523
    if (apr_table_get(r->subprocess_env, "proxy-wstunnel-strip-extra-data")) {
524
        status = proxy_wstunnel_strip_extra_data(r);
525
        if (status != APR_SUCCESS) {
526
	    return HTTP_INTERNAL_SERVER_ERROR;
527
	}
528
    }
529
479
    /* create space for state information */
530
    /* create space for state information */
480
    status = ap_proxy_acquire_connection(scheme, &backend, worker,
531
    status = ap_proxy_acquire_connection(scheme, &backend, worker,
481
                                         r->server);
532
                                         r->server);

Return to bug 57436