From 8ddeed80cf5020644922fd71ca7f0c9220b64f44 Mon Sep 17 00:00:00 2001 From: "roberto@quantal64" Date: Sun, 17 Jun 2012 18:06:53 +0200 Subject: [PATCH] the http router is now websocket friendly --- plugins/http/http.c | 8 ++++++++ plugins/python/uwsgi_pymodule.c | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/plugins/http/http.c b/plugins/http/http.c index 619ac08f..8dfb17d3 100644 --- a/plugins/http/http.c +++ b/plugins/http/http.c @@ -28,6 +28,9 @@ struct uwsgi_http { uint8_t modifier1; struct uwsgi_string_list *http_vars; int manage_expect; + + int raw_body; + int keepalive; #ifdef UWSGI_SSL int https_export_cert; @@ -128,6 +131,8 @@ struct uwsgi_option http_options[] = { {"http-manage-expect", no_argument, 0, "manage the Expect HTTP request header", uwsgi_opt_true, &uhttp.manage_expect, 0}, {"http-keepalive", no_argument, 0, "support HTTP keepalive (non-pipelined) requests (requires backend support)", uwsgi_opt_true, &uhttp.keepalive, 0}, + {"http-raw-body", no_argument, 0, "blindly send HTTP body to backends (required for WebSockets and Icecast support)", uwsgi_opt_true, &uhttp.raw_body, 0}, + {"http-use-code-string", required_argument, 0, "use code string as hostname->server mapper for the http router", uwsgi_opt_corerouter_cs, &uhttp, 0}, {"http-use-socket", optional_argument, 0, "forward request to the specified uwsgi socket", uwsgi_opt_corerouter_use_socket, &uhttp, 0}, {"http-gracetime", required_argument, 0, "retry connections to dead static nodes after the specified amount of seconds", uwsgi_opt_set_int, &uhttp.cr.static_node_gracetime, 0}, @@ -806,6 +811,8 @@ To have a reliable implementation, we need to reset a bunch of values break; } + if (cs->post_cl == 0 && uhttp.raw_body) goto raw; + // avoid pipelined input if (hs->received_body >= cs->post_cl) { break; @@ -816,6 +823,7 @@ To have a reliable implementation, we need to reset a bunch of values len = cs->post_cl - hs->received_body; } +raw: len = send(cs->instance_fd, bbuf, len, 0); if (len <= 0) { diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index 2007819a..a546ff60 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -997,6 +997,11 @@ PyObject *py_uwsgi_unlock(PyObject * self, PyObject * args) { return Py_None; } +PyObject *py_uwsgi_connection_fd(PyObject * self, PyObject * args) { + struct wsgi_request *wsgi_req = current_wsgi_req(); + return PyInt_FromLong(wsgi_req->poll.fd); +} + PyObject *py_uwsgi_embedded_data(PyObject * self, PyObject * args) { char *name; @@ -3130,6 +3135,7 @@ static PyMethodDef uwsgi_advanced_methods[] = { #endif {"connect", py_uwsgi_connect, METH_VARARGS, ""}, + {"connection_fd", py_uwsgi_connection_fd, METH_VARARGS, ""}, {"is_connected", py_uwsgi_is_connected, METH_VARARGS, ""}, {"send", py_uwsgi_send, METH_VARARGS, ""}, {"recv", py_uwsgi_recv, METH_VARARGS, ""},