2016-05-11 22:36:12 +02:00
|
|
|
---
|
|
|
|
title: "mg_set_protocol_http_websocket()"
|
|
|
|
decl_name: "mg_set_protocol_http_websocket"
|
|
|
|
symbol_kind: "func"
|
|
|
|
signature: |
|
|
|
|
void mg_set_protocol_http_websocket(struct mg_connection *nc);
|
|
|
|
---
|
|
|
|
|
2016-07-25 16:52:13 +02:00
|
|
|
Attach built-in HTTP event handler to the given connection.
|
|
|
|
User-defined event handler will receive following extra events:
|
2016-05-11 22:36:12 +02:00
|
|
|
|
|
|
|
- MG_EV_HTTP_REQUEST: HTTP request has arrived. Parsed HTTP request
|
|
|
|
is passed as
|
|
|
|
`struct http_message` through the handler's `void *ev_data` pointer.
|
2016-07-22 17:08:14 +01:00
|
|
|
- MG_EV_HTTP_MULTIPART_REQUEST: A multipart POST request has received.
|
2016-07-25 16:52:13 +02:00
|
|
|
This event is sent before body is parsed. After this user
|
2016-05-11 22:36:12 +02:00
|
|
|
should expect a sequence of MG_EV_HTTP_PART_BEGIN/DATA/END requests.
|
|
|
|
This is also the last time when headers and other request fields are
|
|
|
|
accessible.
|
2016-07-25 16:52:13 +02:00
|
|
|
- MG_EV_HTTP_REPLY: HTTP reply has arrived. Parsed HTTP reply is passed as
|
2016-05-11 22:36:12 +02:00
|
|
|
`struct http_message` through the handler's `void *ev_data` pointer.
|
2016-07-25 16:52:13 +02:00
|
|
|
- MG_EV_HTTP_CHUNK: HTTP chunked-encoding chunk has arrived.
|
|
|
|
Parsed HTTP reply is passed as `struct http_message` through the
|
2016-05-11 22:36:12 +02:00
|
|
|
handler's `void *ev_data` pointer. `http_message::body` would contain
|
|
|
|
incomplete, reassembled HTTP body.
|
2016-07-25 16:52:13 +02:00
|
|
|
It will grow with every new chunk arrived, and
|
|
|
|
potentially can consume a lot of memory. An event handler may process
|
2016-07-22 17:08:14 +01:00
|
|
|
the body as chunks are coming, and signal Mongoose to delete processed
|
2016-05-11 22:36:12 +02:00
|
|
|
body by setting `MG_F_DELETE_CHUNK` in `mg_connection::flags`. When
|
|
|
|
the last zero chunk is received,
|
2016-07-22 17:08:14 +01:00
|
|
|
Mongoose sends `MG_EV_HTTP_REPLY` event with
|
|
|
|
full reassembled body (if handler did not signal to delete chunks) or
|
|
|
|
with empty body (if handler did signal to delete chunks).
|
2016-07-25 16:52:13 +02:00
|
|
|
- MG_EV_WEBSOCKET_HANDSHAKE_REQUEST: server has received websocket handshake
|
2016-05-11 22:36:12 +02:00
|
|
|
request. `ev_data` contains parsed HTTP request.
|
2016-07-25 16:52:13 +02:00
|
|
|
- MG_EV_WEBSOCKET_HANDSHAKE_DONE: server has completed Websocket handshake.
|
2016-05-11 22:36:12 +02:00
|
|
|
`ev_data` is `NULL`.
|
2016-07-25 16:52:13 +02:00
|
|
|
- MG_EV_WEBSOCKET_FRAME: new websocket frame has arrived. `ev_data` is
|
2016-05-11 22:36:12 +02:00
|
|
|
`struct websocket_message *`
|
2016-07-22 17:08:14 +01:00
|
|
|
- MG_EV_HTTP_PART_BEGIN: new part of multipart message is started,
|
|
|
|
extra parameters are passed in mg_http_multipart_part
|
2016-07-25 16:52:13 +02:00
|
|
|
- MG_EV_HTTP_PART_DATA: new portion of data from multiparted message
|
2016-07-22 17:08:14 +01:00
|
|
|
no additional headers are available, only data and data size
|
|
|
|
- MG_EV_HTTP_PART_END: final boundary received, analogue to maybe used to
|
|
|
|
find the end of packet
|
2016-05-11 22:36:12 +02:00
|
|
|
Note: Mongoose should be compiled with MG_ENABLE_HTTP_STREAMING_MULTIPART
|
|
|
|
to enable MG_EV_HTTP_MULTIPART_REQUEST, MG_EV_HTTP_REQUEST_END,
|
|
|
|
MG_EV_HTTP_REQUEST_CANCEL, MG_EV_HTTP_PART_BEGIN, MG_EV_HTTP_PART_DATA,
|
|
|
|
MG_EV_HTTP_PART_END constants
|
|
|
|
|