GNU libmicrohttpd
0.9.29
|
Methods for managing response objects. More...
#include "mhd_options.h"
#include "internal.h"
#include "response.h"
#include "mhd_limits.h"
#include "mhd_sockets.h"
#include "mhd_itc.h"
#include "connection.h"
#include "memorypool.h"
Go to the source code of this file.
Macros | |
#define | MHD_NO_DEPRECATION 1 |
Methods for managing response objects.
Definition in file response.c.
#define MHD_NO_DEPRECATION 1 |
Definition at line 26 of file response.c.
|
static |
Add a header or footer line to the response.
response | response to add a header to |
kind | header or footer |
header | the header to add |
content | value to add |
Definition at line 63 of file response.c.
References MHD_Response::first_header, MHD_HTTP_Header::header, MHD_HTTP_Header::kind, MHD_NO, MHD_YES, MHD_HTTP_Header::next, NULL, and MHD_HTTP_Header::value.
Referenced by MHD_add_response_footer(), and MHD_add_response_header().
|
static |
Given a file descriptor, read data from the file to generate the response.
cls | pointer to the response |
pos | offset in the file to access |
buf | where to write the data |
max | number of bytes to write at most |
Definition at line 339 of file response.c.
References MHD_Response::fd, MHD_Response::fd_off, INT32_MAX, MHD_CONTENT_READER_END_OF_STREAM, and MHD_CONTENT_READER_END_WITH_ERROR.
Referenced by MHD_create_response_from_fd_at_offset64().
|
static |
Destroy file reader context. Closes the file descriptor.
cls | pointer to file descriptor |
Definition at line 403 of file response.c.
References MHD_Response::fd.
Referenced by MHD_create_response_from_fd_at_offset64().
_MHD_EXTERN struct MHD_Response* MHD_create_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.
Setting the correct HTTP code (i.e. MHD_HTTP_SWITCHING_PROTOCOLS) and 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 952 of file response.c.
References MHD_add_response_header(), MHD_destroy_response(), MHD_HTTP_HEADER_CONNECTION, MHD_NO, MHD_SIZE_UNKNOWN, MHD_Response::mutex, NULL, MHD_Response::reference_count, MHD_Response::total_size, MHD_Response::upgrade_handler, and MHD_Response::upgrade_handler_cls.
void MHD_increment_response_rc | ( | struct MHD_Response * | response | ) |
Increments the reference counter for the response.
response | object to modify |
Definition at line 1028 of file response.c.
References MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_Response::mutex, and MHD_Response::reference_count.
Referenced by MHD_queue_response().
int MHD_response_execute_upgrade_ | ( | struct MHD_Response * | response, |
struct MHD_Connection * | connection | ||
) |
We are done sending the header of a given response to the client. Now it is time to perform the upgrade and hand over the connection to the application.
response | the response that was created for an upgrade |
connection | the specific connection we are upgrading |
Definition at line 708 of file response.c.
References _, _MHD_EXTERN, MHD_Connection::client_context, MHD_UpgradeResponseHandle::connection, MHD_Connection::daemon, DLL_insert, EXTRA_CHECK, MHD_EPOLL_STATE_UNREADY, MHD_get_response_header(), MHD_HTTP_HEADER_UPGRADE, MHD_INVALID_SOCKET, MHD_NO, MHD_PANIC, MHD_pool_allocate(), MHD_pool_get_free(), MHD_SCKT_FD_FITS_FDSET_, MHD_socket_close_chk_, MHD_socket_last_strerr_, MHD_socket_nonblocking_(), MHD_suspend_connection(), MHD_USE_EPOLL, MHD_USE_POLL, MHD_USE_THREAD_PER_CONNECTION, MHD_USE_TLS, MHD_YES, NULL, MHD_Daemon::options, MHD_Connection::pool, MHD_Connection::read_buffer, MHD_Connection::read_buffer_offset, RESERVE_EBUF_SIZE, MHD_Connection::socket_fd, MHD_Response::upgrade_handler, MHD_Response::upgrade_handler_cls, and MHD_Connection::urh.
Referenced by MHD_connection_handle_idle().
int MHD_set_response_options | ( | struct MHD_Response * | response, |
enum MHD_ResponseFlags | flags, | ||
... | |||
) |
Set special flags and options for a response.
response | the response to modify |
flags | to set for the response |
... | MHD_RO_END terminated list of options |
Definition at line 303 of file response.c.
References MHD_Response::flags, MHD_NO, MHD_RO_END, and MHD_YES.
_MHD_EXTERN int MHD_upgrade_action | ( | struct MHD_UpgradeResponseHandle * | urh, |
enum MHD_UpgradeAction | action, | ||
... | |||
) |
This connection-specific callback is provided by MHD to applications (unusual) during the MHD_UpgradeHandler. It allows applications to perform 'special' actions on the underlying socket from the upgrade.
urh | the handle identifying the connection to perform the upgrade action on. |
action | which action should be performed |
... | arguments to the action (depends on the action) |
Definition at line 625 of file response.c.
References _, MHD_UpgradeResponseHandle::connection, MHD_Connection::daemon, MHD_Connection::idle_handler, MHD_cleanup_upgraded_connection_(), MHD_connection_close_(), MHD_CONNECTION_CLOSED, MHD_CONNECTION_IN_CLEANUP, MHD_CONNECTION_UPGRADE_CLOSED, MHD_destroy_response(), MHD_INVALID_SOCKET, MHD_NO, MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN, MHD_socket_close_chk_, MHD_UPGRADE_ACTION_CLOSE, MHD_USE_THREAD_PER_CONNECTION, MHD_USE_TLS, MHD_YES, NULL, MHD_Daemon::options, MHD_Connection::response, MHD_Daemon::shutdown, MHD_Connection::socket_fd, MHD_Connection::state, and MHD_UpgradeResponseHandle::was_closed.