GNU libmicrohttpd 1.0.2
Loading...
Searching...
No Matches
generation of responses

Typedefs

typedef void(* MHD_ContentReaderFreeCallback) (void *cls)

Enumerations

enum  MHD_ResponseMemoryMode { MHD_RESPMEM_PERSISTENT , MHD_RESPMEM_MUST_FREE , MHD_RESPMEM_MUST_COPY }

Functions

_MHD_EXTERN enum MHD_Result MHD_queue_response (struct MHD_Connection *connection, unsigned int status_code, struct MHD_Response *response)
_MHD_EXTERN struct MHD_ResponseMHD_create_response_from_callback (uint64_t size, size_t block_size, MHD_ContentReaderCallback crc, void *crc_cls, MHD_ContentReaderFreeCallback crfc)
 _MHD_DEPR_FUNC ("MHD_create_response_from_data() is deprecated, use MHD_create_response_from_buffer()") _MHD_EXTERN struct MHD_Response *MHD_create_response_from_data(size_t size
_MHD_EXTERN struct MHD_ResponseMHD_create_response_from_buffer (size_t size, void *buffer, enum MHD_ResponseMemoryMode mode)
_MHD_EXTERN struct MHD_ResponseMHD_create_response_from_buffer_static (size_t size, const void *buffer)
_MHD_EXTERN struct MHD_ResponseMHD_create_response_from_buffer_copy (size_t size, const void *buffer)
_MHD_EXTERN struct MHD_ResponseMHD_create_response_from_buffer_with_free_callback (size_t size, void *buffer, MHD_ContentReaderFreeCallback crfc)
_MHD_EXTERN struct MHD_ResponseMHD_create_response_from_buffer_with_free_callback_cls (size_t size, const void *buffer, MHD_ContentReaderFreeCallback crfc, void *crfc_cls)
_MHD_EXTERN struct MHD_ResponseMHD_create_response_from_fd (size_t size, int fd)
_MHD_EXTERN struct MHD_ResponseMHD_create_response_from_pipe (int fd)
_MHD_EXTERN struct MHD_ResponseMHD_create_response_from_fd64 (uint64_t size, int fd)
 _MHD_DEPR_FUNC ("Function MHD_create_response_from_fd_at_offset() is deprecated, use MHD_create_response_from_fd_at_offset64()") _MHD_EXTERN struct MHD_Response *MHD_create_response_from_fd_at_offset(size_t size
_MHD_EXTERN struct MHD_ResponseMHD_create_response_from_fd_at_offset64 (uint64_t size, int fd, uint64_t offset)
_MHD_EXTERN struct MHD_ResponseMHD_create_response_from_iovec (const struct MHD_IoVec *iov, unsigned int iovcnt, MHD_ContentReaderFreeCallback free_cb, void *cls)
_MHD_EXTERN struct MHD_ResponseMHD_create_response_empty (enum MHD_ResponseFlags flags)
_MHD_EXTERN void MHD_destroy_response (struct MHD_Response *response)
_MHD_EXTERN enum MHD_Result MHD_add_response_header (struct MHD_Response *response, const char *header, const char *content)
_MHD_EXTERN enum MHD_Result MHD_add_response_footer (struct MHD_Response *response, const char *footer, const char *content)
_MHD_EXTERN enum MHD_Result MHD_del_response_header (struct MHD_Response *response, const char *header, const char *content)
_MHD_EXTERN int MHD_get_response_headers (struct MHD_Response *response, MHD_KeyValueIterator iterator, void *iterator_cls)
_MHD_EXTERN const char * MHD_get_response_header (struct MHD_Response *response, const char *key)
struct MHD_HTTP_Res_HeaderMHD_get_response_element_n_ (struct MHD_Response *response, enum MHD_ValueKind kind, const char *key, size_t key_len)
_MHD_EXTERN 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_data (size_t size, void *data, int must_free, int must_copy)

Variables

enum MHD_HdrLineReadRes_ _MHD_FIXED_ENUM

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 2889 of file microhttpd.h.

Enumeration Type Documentation

◆ MHD_ResponseMemoryMode

Specification for how MHD should treat the memory buffer given for the response.

Enumerator
MHD_RESPMEM_PERSISTENT 

Buffer is a persistent (static/global) buffer that won't change for at least the lifetime of the response, MHD should just use it, not free it, not copy it, just keep an alias to it.

MHD_RESPMEM_MUST_FREE 

Buffer is heap-allocated with malloc() (or equivalent) and should be freed by MHD after processing the response has concluded (response reference counter reaches zero). The more portable way to automatically free the buffer is function MHD_create_response_from_buffer_with_free_callback() with '&free' as crfc parameter as it does not require to use the same runtime library.

Warning
It is critical to make sure that the same C-runtime library is used by both application and MHD (especially important for W32).
MHD_RESPMEM_MUST_COPY 

Buffer is in transient memory, but not on the heap (for example, on the stack or non-malloc() allocated) and only valid during the call to MHD_create_response_from_buffer. MHD must make its own private copy of the data for processing.

Definition at line 3985 of file microhttpd.h.

Function Documentation

◆ _MHD_DEPR_FUNC() [1/2]

_MHD_DEPR_FUNC ( "Function MHD_create_response_from_fd_at_offset() is deprecated,
use MHD_create_response_from_fd_at_offset64()"  )

Create a response object with the content of provided file with specified offset used as the response body.

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

If response object is used to answer HEAD request then the body of the response is not used, while all headers (including automatic headers) are used.

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)

References _MHD_EXTERN.

◆ _MHD_DEPR_FUNC() [2/2]

_MHD_DEPR_FUNC ( "MHD_create_response_from_data() is deprecated,
use MHD_create_response_from_buffer()"  )

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

If response object is used to answer HEAD request then the body of the response is not used, while all headers (including automatic headers) are used.

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 may be released anytime after this call returns
Returns
NULL on error (i.e. invalid arguments, out of memory)

References _MHD_EXTERN.

◆ MHD_add_response_footer()

_MHD_EXTERN enum MHD_Result 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 715 of file response.c.

References add_response_entry(), and MHD_FOOTER_KIND.

Here is the call graph for this function:

◆ MHD_add_response_header()

_MHD_EXTERN enum MHD_Result MHD_add_response_header ( struct MHD_Response * response,
const char * header,
const char * content )

Add a header line to the response.

When reply is generated with queued response, some headers are generated automatically. Automatically generated headers are only sent to the client, but not added back to the response object.

The list of automatic headers:

  • "Date" header is added automatically unless already set by this function
    See also
    MHD_USE_SUPPRESS_DATE_NO_CLOCK
  • "Content-Length" is added automatically when required, attempt to set it manually by this function is ignored.
    See also
    MHD_RF_INSANITY_HEADER_CONTENT_LENGTH
  • "Transfer-Encoding" with value "chunked" is added automatically, when chunked transfer encoding is used automatically. Same header with the same value can be set manually by this function to enforce chunked encoding, however for HTTP/1.0 clients chunked encoding will not be used and manually set "Transfer-Encoding" header is automatically removed for HTTP/1.0 clients
  • "Connection" may be added automatically with value "Keep-Alive" (only for HTTP/1.0 clients) or "Close". The header "Connection" with value "Close" could be set by this function to enforce closure of the connection after sending this response. "Keep-Alive" cannot be enforced and will be removed automatically.
    See also
    MHD_RF_SEND_KEEP_ALIVE_HEADER
    Some headers are pre-processed by this function:
  • "Connection" headers are combined into single header entry, value is normilised, "Keep-Alive" tokens are removed.
  • "Transfer-Encoding" header: the only one header is allowed, the only allowed value is "chunked".
  • "Date" header: the only one header is allowed, the second added header replaces the first one.
  • "Content-Length" application-defined header is not allowed.
    See also
    MHD_RF_INSANITY_HEADER_CONTENT_LENGTH
    Headers are used in order as they were added.
Parameters
responsethe response to add a header to
headerthe header name to add, no need to be static, an internal copy will be created automatically
contentthe header value to add, no need to be static, an internal copy will be created automatically
Returns
MHD_YES on success, MHD_NO on error (i.e. invalid header or content format), or out of memory

Definition at line 620 of file response.c.

References _MHD_remove_header, add_response_entry(), add_response_header_connection(), MHD_Response::flags, MHD_Response::flags_auto, MHD_HTTP_Res_Header::header, mhd_assert, MHD_get_response_element_n_(), MHD_HEADER_KIND, MHD_HTTP_HEADER_CONNECTION, MHD_HTTP_HEADER_CONTENT_LENGTH, MHD_HTTP_HEADER_DATE, MHD_HTTP_HEADER_TRANSFER_ENCODING, MHD_NO, MHD_RAF_HAS_CONTENT_LENGTH, MHD_RAF_HAS_DATE_HDR, MHD_RAF_HAS_TRANS_ENC_CHUNKED, MHD_RF_HEAD_ONLY_RESPONSE, MHD_RF_INSANITY_HEADER_CONTENT_LENGTH, MHD_STATICSTR_LEN_, MHD_str_equal_caseless_(), MHD_YES, NULL, and MHD_HTTP_Res_Header::value.

Referenced by MHD_queue_basic_auth_required_response3().

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

◆ MHD_create_response_empty()

_MHD_EXTERN struct MHD_Response * MHD_create_response_empty ( enum MHD_ResponseFlags flags)

Create a response object with empty (zero size) body.

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

This function is a faster equivalent of MHD_create_response_from_buffer call with zero size combined with call of MHD_set_response_options.

Parameters
flagsthe flags for the new response object
Returns
NULL on error (i.e. invalid arguments, out of memory), the pointer to the created response object otherwise
Note
Available since MHD_VERSION 0x00097701

Definition at line 1826 of file response.c.

References MHD_Response::fd, MHD_Response::flags, MHD_calloc_(), MHD_mutex_init_, NULL, and MHD_Response::reference_count.

Here is the call graph for this function:

◆ MHD_create_response_from_buffer()

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

Create a response object with the content of provided buffer used as the response body.

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

If response object is used to answer HEAD request then the body of the response is not used, while all headers (including automatic headers) are used.

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 1465 of file response.c.

References MHD_create_response_from_buffer_copy(), MHD_create_response_from_buffer_with_free_callback_cls(), MHD_RESPMEM_MUST_COPY, MHD_RESPMEM_MUST_FREE, and NULL.

Referenced by MHD_create_response_from_data().

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

◆ MHD_create_response_from_buffer_copy()

_MHD_EXTERN struct MHD_Response * MHD_create_response_from_buffer_copy ( size_t size,
const void * buffer )

Create a response object with the content of provided temporal buffer used as the response body.

An internal copy of the buffer will be made automatically, so buffer have to be valid only during the call of this function (as a typical example: buffer is a local (non-static) array).

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

If response object is used to answer HEAD request then the body of the response is not used, while all headers (including automatic headers) are used.

Parameters
sizethe size of the data in buffer, can be zero
bufferthe buffer with the data for the response body, can be NULL if size is zero
Returns
NULL on error (i.e. invalid arguments, out of memory)
Note
Available since MHD_VERSION 0x00097701

Definition at line 1540 of file response.c.

References MHD_Response::data_buffer_size, MHD_create_response_from_buffer_with_free_callback_cls(), and NULL.

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_buffer_static()

_MHD_EXTERN struct MHD_Response * MHD_create_response_from_buffer_static ( size_t size,
const void * buffer )

Create a response object with the content of provided statically allocated buffer used as the response body.

The buffer must be valid for the lifetime of the response. The easiest way to achieve this is to use a statically allocated buffer.

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

If response object is used to answer HEAD request then the body of the response is not used, while all headers (including automatic headers) are used.

Parameters
sizethe size of the data in buffer, can be zero
bufferthe buffer with the data for the response body, can be NULL if size is zero
Returns
NULL on error (i.e. invalid arguments, out of memory)
Note
Available since MHD_VERSION 0x00097701

Definition at line 1507 of file response.c.

References MHD_create_response_from_buffer_with_free_callback_cls(), and NULL.

Referenced by transmit_error_response_len().

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

◆ MHD_create_response_from_buffer_with_free_callback()

_MHD_EXTERN struct MHD_Response * MHD_create_response_from_buffer_with_free_callback ( size_t size,
void * buffer,
MHD_ContentReaderFreeCallback crfc )

Create a response object with the content of provided buffer used as the response body.

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

If response object is used to answer HEAD request then the body of the response is not used, while all headers (including automatic headers) are used.

Parameters
sizesize of the data portion of the response
buffersize bytes containing the response's data portion
crfcfunction to call to free the buffer
Returns
NULL on error (i.e. invalid arguments, out of memory)
Note
Available since MHD_VERSION 0x00096000

Create a response object with the content of provided buffer used as the response body.

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

If response object is used to answer HEAD request then the body of the response is not used, while all headers (including automatic headers) are used.

Parameters
sizesize of the data portion of the response
buffersize bytes containing the response's data portion
crfcfunction to call to free the buffer
Returns
NULL on error (i.e. invalid arguments, out of memory)

Definition at line 1593 of file response.c.

References MHD_Response::crfc, and MHD_create_response_from_buffer_with_free_callback_cls().

Here is the call graph for this function:

◆ MHD_create_response_from_buffer_with_free_callback_cls()

_MHD_EXTERN struct MHD_Response * MHD_create_response_from_buffer_with_free_callback_cls ( size_t size,
const void * buffer,
MHD_ContentReaderFreeCallback crfc,
void * crfc_cls )

Create a response object with the content of provided buffer used as the response body.

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

If response object is used to answer HEAD request then the body of the response is not used, while all headers (including automatic headers) are used.

Parameters
sizesize of the data portion of the response
buffersize bytes containing the response's data portion
crfcfunction to call to cleanup, if set to NULL then callback is not called
crfc_clsan argument for crfc
Returns
NULL on error (i.e. invalid arguments, out of memory)
Note
Available since MHD_VERSION 0x00097302
'const' qualifier is used for buffer since MHD_VERSION 0x00097701

Definition at line 1627 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_init_, MHD_SIZE_UNKNOWN, NULL, MHD_Response::reference_count, and MHD_Response::total_size.

Referenced by MHD_create_response_from_buffer(), MHD_create_response_from_buffer_copy(), MHD_create_response_from_buffer_static(), and MHD_create_response_from_buffer_with_free_callback().

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

◆ MHD_create_response_from_callback()

_MHD_EXTERN 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.

If response object is used to answer HEAD request then the body of the response is not used, while all headers (including automatic headers) are used.

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 987 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_mutex_init_, NULL, MHD_Response::reference_count, and MHD_Response::total_size.

Referenced by MHD_create_response_from_fd_at_offset64(), and MHD_create_response_from_pipe().

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

◆ MHD_create_response_from_data()

_MHD_EXTERN 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.

If response object is used to answer HEAD request then the body of the response is not used, while all headers (including automatic headers) are used.

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 may be released anytime after this call returns
Returns
NULL on error (i.e. invalid arguments, out of memory)

Definition at line 1429 of file response.c.

References data, MHD_create_response_from_buffer(), MHD_RESPMEM_MUST_COPY, MHD_RESPMEM_MUST_FREE, MHD_RESPMEM_PERSISTENT, must_copy, and must_free.

Here is the call graph for this function:

◆ MHD_create_response_from_fd()

_MHD_EXTERN struct MHD_Response * MHD_create_response_from_fd ( size_t size,
int fd )

Create a response object with the content of provided file used as the response body.

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

If response object is used to answer HEAD request then the body of the response is not used, while all headers (including automatic headers) are used.

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
Returns
NULL on error (i.e. invalid arguments, out of memory)

Create a response object with the content of provided file used as the response body.

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

If response object is used to answer HEAD request then the body of the response is not used, while all headers (including automatic headers) are used.

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 1370 of file response.c.

References fd, 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 with the content of provided file used as the response body.

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

If response object is used to answer HEAD request then the body of the response is not used, while all headers (including automatic headers) are used.

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 1400 of file response.c.

References fd, and MHD_create_response_from_fd_at_offset64().

Here is the call graph for this function:

◆ MHD_create_response_from_fd_at_offset()

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

Create a response object with the content of provided file with specified offset used as the response body.

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

If response object is used to answer HEAD request then the body of the response is not used, while all headers (including automatic headers) are used.

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 1248 of file response.c.

References fd, MHD_create_response_from_fd_at_offset64(), NULL, and offset.

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 with the content of provided file with specified offset used as the response body.

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

If response object is used to answer HEAD request then the body of the response is not used, while all headers (including automatic headers) are used.

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 1284 of file response.c.

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

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_create_response_from_iovec()

_MHD_EXTERN struct MHD_Response * MHD_create_response_from_iovec ( const struct MHD_IoVec * iov,
unsigned int iovcnt,
MHD_ContentReaderFreeCallback free_cb,
void * cls )

Create a response object with an array of memory buffers used as the response body.

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

If response object is used to answer HEAD request then the body of the response is not used, while all headers (including automatic headers) are used.

Parameters
iovthe array for response data buffers, an internal copy of this will be made
iovcntthe number of elements in iov
free_cbthe callback to clean up any data associated with iov when the response is destroyed.
clsthe argument passed to free_cb
Returns
NULL on error (i.e. invalid arguments, out of memory)
Note
Available since MHD_VERSION 0x00097204

Create a response object with an array of memory buffers used as the response body.

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

If response object is used to answer HEAD request then the body of the response is not used, while all headers (including automatic headers) are used.

Parameters
iovthe array for response data buffers, an internal copy of this will be made
iovcntthe number of elements in iov
free_cbthe callback to clean up any data associated with iov when the response is destroyed.
clsthe argument passed to free_cb
Returns
NULL on error (i.e. invalid arguments, out of memory)

< Index in the copy of iov

Definition at line 1682 of file response.c.

References _MHD_DROP_CONST, MHD_Response::crc_cls, MHD_Response::crfc, MHD_Response::data, MHD_Response::data_iov, MHD_Response::data_iovcnt, MHD_Response::data_size, MHD_Response::fd, INT_MAX, MHD_IoVec::iov_base, MHD_IoVec::iov_len, mhd_assert, MHD_calloc_(), MHD_IOV_ELMN_MAX_SIZE, MHD_mutex_destroy_chk_, MHD_mutex_init_, NULL, MHD_Response::reference_count, SSIZE_MAX, and MHD_Response::total_size.

Here is the call graph for this function:

◆ MHD_create_response_from_pipe()

_MHD_EXTERN struct MHD_Response * MHD_create_response_from_pipe ( int fd)

Create a response object with the response body created by reading the provided pipe.

The response object can be extended with header information and then be used ONLY ONCE.

If response object is used to answer HEAD request then the body of the response is not used, while all headers (including automatic headers) are used.

Parameters
fdfile descriptor referring to a read-end of a pipe 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)
Note
Available since MHD_VERSION 0x00097102

Create a response object with the response body created by reading the provided pipe.

The response object can be extended with header information and then be used ONLY ONCE.

If response object is used to answer HEAD request then the body of the response is not used, while all headers (including automatic headers) are used.

Parameters
fdfile descriptor referring to a read-end of a pipe 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 1335 of file response.c.

References MHD_Response::crc_cls, fd, MHD_Response::fd, free_callback(), MHD_Response::is_pipe, MHD_create_response_from_callback(), MHD_FILE_READ_BLOCK_SIZE, MHD_SIZE_UNKNOWN, NULL, and pipe_reader().

Here is the call graph for this function:

◆ MHD_del_response_header()

_MHD_EXTERN enum MHD_Result MHD_del_response_header ( struct MHD_Response * response,
const char * header,
const char * content )

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

For "Connection" headers this function remove all tokens from existing value. Successful result means that at least one token has been removed. If all tokens are removed from "Connection" header, the empty "Connection" header removed.

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 741 of file response.c.

References _MHD_remove_header, del_response_header_connection(), MHD_Response::first_header, MHD_Response::flags_auto, MHD_HTTP_Res_Header::header, MHD_HTTP_Res_Header::header_size, MHD_get_response_element_n_(), MHD_HEADER_KIND, MHD_HTTP_HEADER_CONNECTION, MHD_HTTP_HEADER_CONTENT_LENGTH, MHD_HTTP_HEADER_DATE, MHD_HTTP_HEADER_TRANSFER_ENCODING, MHD_NO, MHD_RAF_HAS_CONNECTION_HDR, MHD_RAF_HAS_CONTENT_LENGTH, MHD_RAF_HAS_DATE_HDR, MHD_RAF_HAS_TRANS_ENC_CHUNKED, MHD_STATICSTR_LEN_, MHD_str_equal_caseless_bin_n_(), MHD_YES, MHD_HTTP_Res_Header::next, NULL, MHD_HTTP_Res_Header::value, and MHD_HTTP_Res_Header::value_size.

Here is the call graph for this function:

◆ MHD_destroy_response()

_MHD_EXTERN 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 2289 of file response.c.

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

Referenced by cleanup_connection(), connection_reset(), MHD_cleanup_connections(), MHD_connection_close_(), MHD_connection_handle_idle(), and transmit_error_response_len().

Here is the caller graph for this function:

◆ MHD_get_response_element_n_()

struct MHD_HTTP_Res_Header * MHD_get_response_element_n_ ( struct MHD_Response * response,
enum MHD_ValueKind kind,
const char * key,
size_t key_len )

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

Function returns the first found element.

Parameters
responseresponse to query
kindthe kind of element: header or footer
keythe key which header to get
key_lenthe length of the key
Returns
NULL if header element does not exist

Definition at line 889 of file response.c.

References MHD_Response::first_header, MHD_HTTP_Res_Header::header, MHD_HTTP_Res_Header::header_size, MHD_HTTP_Res_Header::kind, mhd_assert, MHD_str_equal_caseless_bin_n_(), MHD_HTTP_Res_Header::next, and NULL.

Referenced by add_response_header_connection(), del_response_header_connection(), MHD_add_response_header(), and MHD_del_response_header().

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

◆ MHD_get_response_header()

_MHD_EXTERN 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 855 of file response.c.

References MHD_Response::first_header, MHD_HTTP_Res_Header::header, MHD_HTTP_Res_Header::header_size, MHD_str_equal_caseless_bin_n_(), MHD_HTTP_Res_Header::next, NULL, and MHD_HTTP_Res_Header::value.

Here is the call graph for this function:

◆ MHD_get_response_headers()

_MHD_EXTERN 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; may be NULL (then just count headers)
iterator_clsextra argument to iterator
Returns
number of entries iterated over

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 823 of file response.c.

References MHD_Response::first_header, MHD_HTTP_Res_Header::header, MHD_HTTP_Res_Header::kind, MHD_NO, MHD_HTTP_Res_Header::next, NULL, and MHD_HTTP_Res_Header::value.

◆ MHD_queue_response()

_MHD_EXTERN enum MHD_Result 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).

For any active connection this function must be called only by MHD_AccessHandlerCallback callback.

For suspended connection this function can be called at any moment (this behaviour is deprecated and will be removed!). Response will be sent as soon as connection is resumed.

For single thread environment, when MHD is used in "external polling" mode (without MHD_USE_SELECT_INTERNALLY) this function can be called any time (this behaviour is deprecated and will be removed!).

If HTTP specifications require use no body in reply, like status_code with value 1xx, the response body is automatically not sent even if it is present in the response. No "Content-Length" or "Transfer-Encoding" headers are generated and added.

When the response is used to respond HEAD request or used with status_code MHD_HTTP_NOT_MODIFIED, then response body is not sent, but "Content-Length" header is added automatically based the size of the body in the response. If body size it set to MHD_SIZE_UNKNOWN or chunked encoding is enforced then "Transfer-Encoding: chunked" header (for HTTP/1.1 only) is added instead of "Content-Length" header. For example, if response with zero-size body is used for HEAD request, then "Content-Length: 0" is added automatically to reply headers.

See also
MHD_RF_HEAD_ONLY_RESPONSE

In situations, where reply body is required, like answer for the GET request with status_code MHD_HTTP_OK, headers "Content-Length" (for known body size) or "Transfer-Encoding: chunked" (for MHD_SIZE_UNKNOWN with HTTP/1.1) are added automatically. In practice, the same response object can be used to respond to both HEAD and GET requests.

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

Definition at line 7850 of file connection.c.

References _, MHD_Connection::daemon, MHD_Connection::discard_request, MHD_Response::fd, MHD_Response::first_header, MHD_Response::flags, MHD_Response::flags_auto, MHD_HTTP_Res_Header::header, MHD_Request::http_mthd, MHD_Request::http_ver, MHD_Connection::in_access_handler, MHD_Connection::in_idle, MHD_Response::is_pipe, is_reply_body_needed(), MHD_ALLOW_UPGRADE, mhd_assert, MHD_CONNECTION_FULL_REQ_RECEIVED, MHD_connection_handle_idle(), MHD_CONNECTION_HEADERS_PROCESSED, MHD_CONNECTION_START_REPLY, MHD_D_IS_USING_THREADS_, MHD_HTTP_HEADER_CONNECTION, MHD_HTTP_MTHD_CONNECT, MHD_HTTP_MTHD_HEAD, MHD_HTTP_NO_CONTENT, MHD_HTTP_NOT_MODIFIED, MHD_HTTP_OK, MHD_HTTP_SWITCHING_PROTOCOLS, MHD_HTTP_VER_1_0, MHD_ICY_FLAG, MHD_increment_response_rc(), MHD_IS_HTTP_VER_1_1_COMPAT, MHD_NO, MHD_RAF_HAS_CONNECTION_HDR, MHD_RAF_HAS_CONTENT_LENGTH, MHD_RF_HEAD_ONLY_RESPONSE, MHD_RF_HTTP_1_0_COMPATIBLE_STRICT, MHD_RF_HTTP_1_0_SERVER, MHD_RF_INSANITY_HEADER_CONTENT_LENGTH, MHD_SEND_SPIPE_SUPPRESS_NEEDED, MHD_str_equal_caseless_(), MHD_str_has_s_token_caseless_, MHD_thread_handle_ID_is_current_thread_, MHD_update_last_activity_(), MHD_USE_TLS, MHD_YES, NULL, MHD_Daemon::options, MHD_Request::remaining_upload_size, MHD_Reply::response, MHD_Reply::responseCode, MHD_Reply::responseIcy, MHD_Connection::rp, RP_BODY_HEADERS_ONLY, MHD_Connection::rq, MHD_Reply::rsp_write_position, MHD_Daemon::shutdown, MHD_Daemon::sigpipe_blocked, MHD_Connection::sk_spipe_suppress, MHD_Connection::state, MHD_Connection::suspended, MHD_Response::total_size, and MHD_HTTP_Res_Header::value.

Referenced by MHD_queue_basic_auth_required_response3(), queue_auth_required_response3_inner(), and transmit_error_response_len().

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

Variable Documentation

◆ _MHD_FIXED_ENUM

enum MHD_ResponseMemoryMode _MHD_FIXED_ENUM