MINOR: stream/mux: implement websocket stream flag
Define a new stream flag SF_WEBSOCKET and a new cs flag CS_FL_WEBSOCKET.
The conn-stream flag is first set by h1/h2 muxes if the request is a
valid websocket upgrade. The flag is then converted to SF_WEBSOCKET on
the stream creation.
This will be useful to properly manage websocket streams in
connect_server().
(cherry picked from commit 90ac605ef35d60323cfe4bc26cd56c2f97dc2277)
[ad: remove non present flag from context]
Signed-off-by: Amaury Denoyelle <adenoyelle@haproxy.com>
diff --git a/include/haproxy/connection-t.h b/include/haproxy/connection-t.h
index a0cfed7..7ad89e6 100644
--- a/include/haproxy/connection-t.h
+++ b/include/haproxy/connection-t.h
@@ -86,6 +86,9 @@
* the stream-interface :
*/
CS_FL_NOT_FIRST = 0x00100000, /* this stream is not the first one */
+
+ /* flags set by the mux relayed to the stream */
+ CS_FL_WEBSOCKET = 0x00200000, /* websocket stream */
};
/* cs_shutr() modes */
diff --git a/include/haproxy/stream-t.h b/include/haproxy/stream-t.h
index 9499e94..0b07c15 100644
--- a/include/haproxy/stream-t.h
+++ b/include/haproxy/stream-t.h
@@ -89,6 +89,7 @@
#define SF_SRV_REUSED 0x00100000 /* the server-side connection was reused */
+#define SF_WEBSOCKET 0x00400000 /* websocket stream */
/* flags for the proxy of the master CLI */
/* 0x1.. to 0x3 are reserved for ACCESS_LVL_MASK */
diff --git a/src/mux_h1.c b/src/mux_h1.c
index 3974e53..2de424a 100644
--- a/src/mux_h1.c
+++ b/src/mux_h1.c
@@ -593,6 +593,9 @@
if (h1s->flags & H1S_F_NOT_FIRST)
cs->flags |= CS_FL_NOT_FIRST;
+ if (h1s->req.flags & H1_MF_UPG_WEBSOCKET)
+ cs->flags |= CS_FL_WEBSOCKET;
+
if (stream_create_from_cs(cs, input) < 0) {
TRACE_DEVEL("leaving on stream creation failure", H1_EV_STRM_NEW|H1_EV_STRM_END|H1_EV_STRM_ERR, h1s->h1c->conn, h1s);
goto err;
diff --git a/src/mux_h2.c b/src/mux_h2.c
index 278636a..6bf5c14 100644
--- a/src/mux_h2.c
+++ b/src/mux_h2.c
@@ -1508,7 +1508,7 @@
* responsible of it. On error, <input> is unchanged, thus the mux must still
* take care of it.
*/
-static struct h2s *h2c_frt_stream_new(struct h2c *h2c, int id, struct buffer *input)
+static struct h2s *h2c_frt_stream_new(struct h2c *h2c, int id, struct buffer *input, uint32_t flags)
{
struct session *sess = h2c->conn->owner;
struct conn_stream *cs;
@@ -1532,6 +1532,12 @@
cs->ctx = h2s;
h2c->nb_cs++;
+ /* FIXME wrong analogy between ext-connect and websocket, this need to
+ * be refine.
+ */
+ if (flags & H2_SF_EXT_CONNECT_RCVD)
+ cs->flags |= CS_FL_WEBSOCKET;
+
if (stream_create_from_cs(cs, input) < 0)
goto out_free_cs;
@@ -2746,7 +2752,7 @@
* Xfer the rxbuf to the stream. On success, the new stream owns the
* rxbuf. On error, it is released here.
*/
- h2s = h2c_frt_stream_new(h2c, h2c->dsi, &rxbuf);
+ h2s = h2c_frt_stream_new(h2c, h2c->dsi, &rxbuf, flags);
if (!h2s) {
h2s = (struct h2s*)h2_refused_stream;
goto send_rst;
diff --git a/src/stream.c b/src/stream.c
index cb2c754..b10800f 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -465,6 +465,9 @@
s->si[0].flags |= SI_FL_CLEAN_ABRT;
if (cs->conn->mux->flags & MX_FL_HTX)
s->flags |= SF_HTX;
+
+ if (cs->flags & CS_FL_WEBSOCKET)
+ s->flags |= SF_WEBSOCKET;
}
/* Set SF_HTX flag for HTTP frontends. */
if (sess->fe->mode == PR_MODE_HTTP)