GNU libmicrohttpd
0.9.72
|
implementation of MHD_response_for_upgrade() More...
#include "internal.h"
Go to the source code of this file.
Functions | |
struct MHD_Response * | MHD_response_for_upgrade (MHD_UpgradeHandler upgrade_handler, void *upgrade_handler_cls) |
implementation of MHD_response_for_upgrade()
Definition in file response_for_upgrade.c.
struct MHD_Response* MHD_response_for_upgrade | ( | MHD_UpgradeHandler | upgrade_handler, |
void * | upgrade_handler_cls | ||
) |
Create a response object that can be used for 101 UPGRADE responses, for example to implement WebSockets. After sending the response, control over the data stream is given to the callback (which can then, for example, start some bi-directional communication). If the response is queued for multiple connections, the callback will be called for each connection. The callback will ONLY be called after the response header was successfully passed to the OS; if there are communication errors before, the usual MHD connection error handling code will be performed.
MHD will automatically set the correct HTTP status code (MHD_HTTP_SWITCHING_PROTOCOLS). Setting correct HTTP headers for the upgrade must be done manually (this way, it is possible to implement most existing WebSocket versions using this API; in fact, this API might be useful for any protocol switch, not just WebSockets). Note that draft-ietf-hybi-thewebsocketprotocol-00 cannot be implemented this way as the header "HTTP/1.1 101 WebSocket Protocol Handshake" cannot be generated; instead, MHD will always produce "HTTP/1.1 101 Switching Protocols" (if the response code 101 is used).
As usual, the response object can be extended with header information and then be used any number of times (as long as the header information is not connection-specific).
upgrade_handler | function to call with the "upgraded" socket |
upgrade_handler_cls | closure for upgrade_handler |
Definition at line 59 of file response_for_upgrade.c.
References mhd_assert, MHD_calloc_(), MHD_HTTP_HEADER_CONNECTION, MHD_HTTP_SWITCHING_PROTOCOLS, MHD_mutex_init_, MHD_NO, MHD_response_add_header(), MHD_response_queue_for_destroy(), MHD_SIZE_UNKNOWN, MHD_Response::mutex, NULL, MHD_Response::reference_count, MHD_Response::status_code, and MHD_Response::total_size.