GNU libmicrohttpd  0.9.29
generation of responses

Typedefs

typedef void(* MHD_ContentReaderFreeCallback) (void *cls)
 

Functions

int MHD_queue_response (struct MHD_Connection *connection, unsigned int status_code, struct MHD_Response *response)
 
int MHD_add_response_header (struct MHD_Response *response, const char *header, const char *content)
 
int MHD_add_response_footer (struct MHD_Response *response, const char *footer, const char *content)
 
int MHD_del_response_header (struct MHD_Response *response, const char *header, const char *content)
 
int MHD_get_response_headers (struct MHD_Response *response, MHD_KeyValueIterator iterator, void *iterator_cls)
 
const char * MHD_get_response_header (struct MHD_Response *response, const char *key)
 
struct MHD_ResponseMHD_create_response_from_callback (uint64_t size, size_t block_size, MHD_ContentReaderCallback crc, void *crc_cls, MHD_ContentReaderFreeCallback crfc)
 
struct MHD_ResponseMHD_create_response_from_fd_at_offset (size_t size, int fd, off_t offset)
 
_MHD_EXTERN struct MHD_ResponseMHD_create_response_from_fd_at_offset64 (uint64_t size, int fd, uint64_t offset)
 
struct MHD_ResponseMHD_create_response_from_fd (size_t size, int fd)
 
_MHD_EXTERN struct MHD_ResponseMHD_create_response_from_fd64 (uint64_t size, int fd)
 
struct MHD_ResponseMHD_create_response_from_data (size_t size, void *data, int must_free, int must_copy)
 
struct MHD_ResponseMHD_create_response_from_buffer (size_t size, void *buffer, enum MHD_ResponseMemoryMode mode)
 
void MHD_destroy_response (struct MHD_Response *response)
 

Detailed Description

MHD API used to generate responses.

Typedef Documentation

◆ MHD_ContentReaderFreeCallback

typedef void(* MHD_ContentReaderFreeCallback) (void *cls)

This method is called by libmicrohttpd if we are done with a content reader. It should be used to free resources associated with the content reader.

Parameters
clsclosure

Definition at line 2059 of file microhttpd.h.

Function Documentation

◆ MHD_add_response_footer()

int MHD_add_response_footer ( struct MHD_Response response,
const char *  footer,
const char *  content 
)

Add a footer line to the response.

Parameters
responseresponse to remove a header from
footerthe footer to delete
contentvalue to delete
Returns
MHD_NO on error (i.e. invalid footer or content format).

Definition at line 139 of file response.c.

References add_response_entry(), and MHD_FOOTER_KIND.

Here is the call graph for this function:

◆ MHD_add_response_header()

int MHD_add_response_header ( struct MHD_Response response,
const char *  header,
const char *  content 
)

Add a header line to the response.

Parameters
responseresponse to add a header to
headerthe header to add
contentvalue to add
Returns
MHD_NO on error (i.e. invalid header or content format).

Definition at line 118 of file response.c.

References add_response_entry(), and MHD_HEADER_KIND.

Referenced by MHD_create_response_from_buffer(), MHD_queue_auth_fail_response(), and MHD_queue_basic_auth_fail_response().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_create_response_from_buffer()

struct MHD_Response* MHD_create_response_from_buffer ( size_t  size,
void *  buffer,
enum MHD_ResponseMemoryMode  mode 
)

Create a response object. The response object can be extended with header information and then be used any number of times.

Parameters
sizesize of the data portion of the response
buffersize bytes containing the response's data portion
modeflags for buffer management
Returns
NULL on error (i.e. invalid arguments, out of memory)

Definition at line 658 of file response.c.

References _, _MHD_EXTERN, MHD_Connection::client_context, MHD_Connection::daemon, DLL_insert, EDLL_insert, EXTRA_CHECK, internal_suspend_connection_(), MHD_add_response_header(), MHD_ALLOW_UPGRADE, MHD_calloc_(), MHD_create_response_from_data(), MHD_destroy_response(), MHD_EPOLL_STATE_UNREADY, MHD_get_response_header(), MHD_HTTP_HEADER_CONNECTION, MHD_HTTP_HEADER_UPGRADE, MHD_INVALID_SOCKET, MHD_NO, MHD_PANIC, MHD_pool_allocate(), MHD_pool_get_free(), MHD_response_execute_upgrade_(), MHD_resume_connection(), MHD_SCKT_FD_FITS_FDSET_, MHD_SIZE_UNKNOWN, MHD_socket_close_chk_, MHD_socket_last_strerr_, MHD_socket_nonblocking_(), MHD_USE_EPOLL, MHD_USE_POLL, MHD_USE_THREAD_PER_CONNECTION, MHD_USE_TLS, MHD_YES, MHD_Response::mutex, NULL, MHD_Daemon::options, MHD_Connection::pool, MHD_Connection::read_buffer, MHD_Connection::read_buffer_offset, MHD_Response::reference_count, MHD_Daemon::shutdown, MHD_Connection::socket_fd, MHD_Connection::state, and MHD_Response::total_size.

Referenced by parse_connection_headers(), and transmit_error_response().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_create_response_from_callback()

struct MHD_Response* MHD_create_response_from_callback ( uint64_t  size,
size_t  block_size,
MHD_ContentReaderCallback  crc,
void *  crc_cls,
MHD_ContentReaderFreeCallback  crfc 
)

Create a response object. The response object can be extended with header information and then be used any number of times.

Parameters
sizesize of the data portion of the response, MHD_SIZE_UNKNOWN for unknown
block_sizepreferred block size for querying crc (advisory only, MHD may still call crc using smaller chunks); this is essentially the buffer size used for IO, clients should pick a value that is appropriate for IO and memory performance requirements
crccallback to use to obtain response data
crc_clsextra argument to crc
crfccallback to call to free crc_cls resources
Returns
NULL on error (i.e. invalid arguments, out of memory)

Definition at line 303 of file response.c.

References MHD_Response::crc, MHD_Response::crc_cls, MHD_Response::crfc, MHD_Response::data, MHD_Response::data_buffer_size, MHD_Response::fd, MHD_calloc_(), MHD_Response::mutex, NULL, MHD_Response::reference_count, and MHD_Response::total_size.

Referenced by MHD_create_response_from_fd_at_offset64().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_create_response_from_data()

struct MHD_Response* MHD_create_response_from_data ( size_t  size,
void *  data,
int  must_free,
int  must_copy 
)

Create a response object. The response object can be extended with header information and then be used any number of times.

Parameters
sizesize of the data portion of the response
datathe data itself
must_freelibmicrohttpd should free data when done
must_copylibmicrohttpd must make a copy of data right away, the data maybe released anytime after this call returns
Returns
NULL on error (i.e. invalid arguments, out of memory)

Definition at line 604 of file response.c.

References MHD_Response::crc_cls, MHD_Response::crfc, MHD_Response::data, MHD_Response::data_size, MHD_Response::fd, MHD_calloc_(), MHD_mutex_destroy_chk_, MHD_YES, MHD_Response::mutex, NULL, MHD_Response::reference_count, and MHD_Response::total_size.

Referenced by MHD_create_response_from_buffer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_create_response_from_fd()

struct MHD_Response* MHD_create_response_from_fd ( size_t  size,
int  fd 
)

Create a response object. The response object can be extended with header information and then be used any number of times.

Parameters
sizesize of the data portion of the response
fdfile descriptor referring to a file on disk with the data
Returns
NULL on error (i.e. invalid arguments, out of memory)

Definition at line 557 of file response.c.

References _MHD_EXTERN, and MHD_create_response_from_fd_at_offset64().

Here is the call graph for this function:

◆ MHD_create_response_from_fd64()

_MHD_EXTERN struct MHD_Response* MHD_create_response_from_fd64 ( uint64_t  size,
int  fd 
)

Create a response object. The response object can be extended with header information and then be used any number of times.

Parameters
sizesize of the data portion of the response; sizes larger than 2 GiB may be not supported by OS or MHD build; see ::MHD_FEATURE_LARGE_FILE
fdfile descriptor referring to a file on disk with the data; will be closed when response is destroyed; fd should be in 'blocking' mode
Returns
NULL on error (i.e. invalid arguments, out of memory)

Definition at line 580 of file response.c.

References MHD_create_response_from_fd_at_offset64().

Here is the call graph for this function:

◆ MHD_create_response_from_fd_at_offset()

struct MHD_Response* MHD_create_response_from_fd_at_offset ( size_t  size,
int  fd,
off_t  offset 
)

Create a response object. The response object can be extended with header information and then be used any number of times.

Parameters
sizesize of the data portion of the response
fdfile descriptor referring to a file on disk with the data; will be closed when response is destroyed; fd should be in 'blocking' mode
offsetoffset to start reading from in the file; Be careful! off_t may have been compiled to be a 64-bit variable for MHD, in which case your application also has to be compiled using the same options! Read the MHD manual for more details.
Returns
NULL on error (i.e. invalid arguments, out of memory)

Definition at line 488 of file response.c.

References _MHD_EXTERN, and MHD_create_response_from_fd_at_offset64().

Here is the call graph for this function:

◆ MHD_create_response_from_fd_at_offset64()

_MHD_EXTERN struct MHD_Response* MHD_create_response_from_fd_at_offset64 ( uint64_t  size,
int  fd,
uint64_t  offset 
)

Create a response object. The response object can be extended with header information and then be used any number of times.

Parameters
sizesize of the data portion of the response; sizes larger than 2 GiB may be not supported by OS or MHD build; see ::MHD_FEATURE_LARGE_FILE
fdfile descriptor referring to a file on disk with the data; will be closed when response is destroyed; fd should be in 'blocking' mode
offsetoffset to start reading from in the file; reading file beyond 2 GiB may be not supported by OS or MHD build; see ::MHD_FEATURE_LARGE_FILE
Returns
NULL on error (i.e. invalid arguments, out of memory)

Definition at line 515 of file response.c.

References MHD_Response::crc_cls, MHD_Response::fd, MHD_Response::fd_off, file_reader(), free_callback(), INT32_MAX, MHD_create_response_from_callback(), and NULL.

Referenced by MHD_create_response_from_fd(), MHD_create_response_from_fd64(), and MHD_create_response_from_fd_at_offset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_del_response_header()

int MHD_del_response_header ( struct MHD_Response response,
const char *  header,
const char *  content 
)

Delete a header (or footer) line from the response.

Parameters
responseresponse to remove a header from
headerthe header to delete
contentvalue to delete
Returns
MHD_NO on error (no such header known)

Definition at line 160 of file response.c.

References MHD_Response::first_header, MHD_HTTP_Header::header, MHD_NO, MHD_YES, MHD_HTTP_Header::next, NULL, and MHD_HTTP_Header::value.

◆ MHD_destroy_response()

void MHD_destroy_response ( struct MHD_Response response)

Destroy a response object and associated resources. Note that libmicrohttpd may keep some of the resources around if the response is still in the queue for some clients, so the memory may not necessarily be freed immediately.

Parameters
responseresponse to destroy

Definition at line 1056 of file response.c.

References MHD_Response::crc_cls, MHD_Response::crfc, MHD_Response::first_header, MHD_HTTP_Header::header, MHD_mutex_destroy_chk_, MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_Response::mutex, MHD_HTTP_Header::next, NULL, MHD_Response::reference_count, and MHD_HTTP_Header::value.

Referenced by cleanup_connection(), MHD_cleanup_connections(), MHD_connection_close_(), MHD_connection_handle_idle(), MHD_create_response_from_buffer(), parse_connection_headers(), thread_main_handle_connection(), and transmit_error_response().

Here is the caller graph for this function:

◆ MHD_get_response_header()

const char* MHD_get_response_header ( struct MHD_Response response,
const char *  key 
)

Get a particular header (or footer) from the response.

Parameters
responseresponse to query
keywhich header to get
Returns
NULL if header does not exist

Definition at line 236 of file response.c.

References MHD_Response::first_header, MHD_HTTP_Header::header, MHD_str_equal_caseless_(), MHD_HTTP_Header::next, NULL, and MHD_HTTP_Header::value.

Referenced by build_header_response(), and MHD_create_response_from_buffer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_get_response_headers()

int MHD_get_response_headers ( struct MHD_Response response,
MHD_KeyValueIterator  iterator,
void *  iterator_cls 
)

Get all of the headers (and footers) added to a response.

Parameters
responseresponse to query
iteratorcallback to call on each header; maybe NULL (then just count headers)
iterator_clsextra argument to iterator
Returns
number of entries iterated over

Definition at line 206 of file response.c.

References MHD_Response::first_header, MHD_HTTP_Header::header, MHD_HTTP_Header::kind, MHD_YES, MHD_HTTP_Header::next, NULL, and MHD_HTTP_Header::value.

◆ MHD_queue_response()

int MHD_queue_response ( struct MHD_Connection connection,
unsigned int  status_code,
struct MHD_Response response 
)

Queue a response to be transmitted to the client (as soon as possible but after MHD_AccessHandlerCallback returns).

Parameters
connectionthe connection identifying the client
status_codeHTTP status code (i.e. MHD_HTTP_OK)
responseresponse to transmit
Returns
MHD_NO on error (i.e. reply already sent), MHD_YES on success or if message has been queued

Definition at line 3579 of file connection.c.

References _, MHD_Connection::daemon, MHD_Response::fd, MHD_Connection::in_idle, MHD_Connection::method, MHD_ALLOW_UPGRADE, MHD_CONNECTION_FOOTERS_RECEIVED, MHD_connection_handle_idle(), MHD_CONNECTION_HEADERS_PROCESSED, MHD_HTTP_METHOD_HEAD, MHD_HTTP_METHOD_POST, MHD_HTTP_METHOD_PUT, MHD_HTTP_NO_CONTENT, MHD_HTTP_NOT_MODIFIED, MHD_HTTP_OK, MHD_HTTP_SWITCHING_PROTOCOLS, MHD_increment_response_rc(), MHD_NO, MHD_str_equal_caseless_(), MHD_USE_TLS, MHD_YES, NULL, MHD_Daemon::options, MHD_Connection::read_closed, MHD_Connection::response, MHD_Connection::response_write_position, MHD_Connection::responseCode, MHD_Connection::state, and MHD_Response::total_size.

Referenced by MHD_queue_auth_fail_response(), MHD_queue_basic_auth_fail_response(), parse_connection_headers(), and transmit_error_response().

Here is the call graph for this function:
Here is the caller graph for this function: