Add mg_connect_ws helper

PUBLISHED_FROM=0ff1c9becea2f0842dcf020d2d2ad64a8c5d95ae
This commit is contained in:
Marko Mikulicic authored and rojer committed 2016-03-08 08:44:23 +01:00
1 parent c82ccd6cf7
commit 14e116553f
2 files changed
+161 -34

No files matched your search

+46
View File
@@ -1990,10 +1990,56 @@ void mg_set_protocol_http_websocket(struct mg_connection *nc);
* to fetch, extra_headers` is extra HTTP headers to send or `NULL`.
*
* This function is intended to be used by websocket client.
*
* Note that the Host header is mandatory in HTTP/1.1 and must be
* included in `extra_headers`. `mg_send_websocket_handshake2` offers
* a better API for that.
*
* Deprecated in favour of `mg_send_websocket_handshake2`
*/
void mg_send_websocket_handshake(struct mg_connection *nc, const char *uri,
const char *extra_headers);
/*
* Send websocket handshake to the server.
*
* `nc` must be a valid connection, connected to a server. `uri` is an URI
* to fetch, `host` goes into the `Host` header, `protocol` goes into the
* `Sec-WebSocket-Proto` header (NULL to omit), extra_headers` is extra HTTP
* headers to send or `NULL`.
*
* This function is intended to be used by websocket client.
*/
void mg_send_websocket_handshake2(struct mg_connection *nc, const char *path,
const char *host, const char *protocol,
const char *extra_headers);
/*
* Helper function that creates an outbound WebSocket connection.
*
* `url` is a URL to connect to. It must be properly URL-encoded, e.g. have
* no spaces, etc. By default, `mg_connect_ws()` sends Connection and
* Host headers. `extra_headers` is an extra HTTP headers to send, e.g.
* `"User-Agent: my-app\r\n"`.
* If `protocol` is not NULL, then a `Sec-WebSocket-Protocol` header is sent.
*
* Examples:
*
* [source,c]
* ----
* nc1 = mg_connect_ws(mgr, ev_handler_1, "ws://echo.websocket.org", NULL,
* NULL);
* nc2 = mg_connect_ws(mgr, ev_handler_1, "wss://echo.websocket.org", NULL,
* NULL);
* nc3 = mg_connect_ws(mgr, ev_handler_1, "ws://api.cesanta.com",
* "clubby.cesanta.com", NULL);
* ----
*/
struct mg_connection *mg_connect_ws(struct mg_mgr *mgr,
mg_event_handler_t event_handler,
const char *url, const char *protocol,
const char *extra_headers);
/*
* Send websocket frame to the remote end.
*