diff --git a/doc/microhttpd.texi b/doc/microhttpd.texi index bd0c42a7..81e902db 100644 --- a/doc/microhttpd.texi +++ b/doc/microhttpd.texi @@ -695,6 +695,36 @@ and returns the number of headers. @end deftypefun +@deftypefun int MHD_set_connection_value (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char * key, const char * value) +This function can be used to add an entry to +the HTTP headers of a connection (so that the +MHD_get_connection_values function will return +them -- and the MHD PostProcessor will also +see them). This maybe required in certain +situations (see Mantis #1399) where (broken) +HTTP implementations fail to supply values needed +by the post processor (or other parts of the +application). + +This function MUST only be called from within +the MHD_AccessHandlerCallback (otherwise, access +maybe improperly synchronized). Furthermore, +the client must guarantee that the key and +value arguments are 0-terminated strings that +are NOT freed until the connection is closed. +(The easiest way to do this is by passing only +arguments to permanently allocated strings.). + +@var{connection} is the connection for which +the entry for @var{key} of the given @var{kind} +should be set to the given @var{value}. + +The function returns @code{MHD_NO} if the operation +could not be performed due to insufficient memory +and @code{MHD_YES} on success. +@end deftypefun + + @deftypefun {const char *} MHD_lookup_connection_value (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key) Get a particular header value. If multiple values match the @var{kind}, return one of them (the ``first'', whatever that means). @var{key} must diff --git a/src/daemon/connection.c b/src/daemon/connection.c index a9a1dd76..6cd4b73c 100644 --- a/src/daemon/connection.c +++ b/src/daemon/connection.c @@ -147,6 +147,56 @@ MHD_get_connection_values (struct MHD_Connection *connection, return ret; } +/** + * This function can be used to add an entry to + * the HTTP headers of a connection (so that the + * MHD_get_connection_values function will return + * them -- and the MHD PostProcessor will also + * see them). This maybe required in certain + * situations (see Mantis #1399) where (broken) + * HTTP implementations fail to supply values needed + * by the post processor (or other parts of the + * application). + *
+ * This function MUST only be called from within + * the MHD_AccessHandlerCallback (otherwise, access + * maybe improperly synchronized). Furthermore, + * the client must guarantee that the key and + * value arguments are 0-terminated strings that + * are NOT freed until the connection is closed. + * (The easiest way to do this is by passing only + * arguments to permanently allocated strings.). + * + * @param connection the connection for which a + * value should be set + * @param kind kind of the value + * @param key key for the value + * @param value the value itself + * @return MHD_NO if the operation could not be + * performed due to insufficient memory; + * MHD_YES on success + */ +int +MHD_set_connection_value (struct MHD_Connection *connection, + enum MHD_ValueKind kind, + const char *key, + const char *value) +{ + struct MHD_HTTP_Header * pos; + + pos = MHD_pool_allocate(connection->pool, + sizeof(struct MHD_HTTP_Header), + MHD_NO); + if (pos == NULL) + return MHD_NO; + pos->header = (char*) key; + pos->value = (char*) value; + pos->kind = kind; + pos->next = connection->headers_received; + connection->headers_received = pos; + return MHD_YES; +} + /** * Get a particular header value. If multiple * values match the kind, return any one of them. diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h index cb6993c8..a934c16e 100644 --- a/src/include/microhttpd.h +++ b/src/include/microhttpd.h @@ -790,6 +790,41 @@ MHD_get_connection_values (struct MHD_Connection *connection, enum MHD_ValueKind kind, MHD_KeyValueIterator iterator, void *iterator_cls); +/** + * This function can be used to add an entry to + * the HTTP headers of a connection (so that the + * MHD_get_connection_values function will return + * them -- and the MHD PostProcessor will also + * see them). This maybe required in certain + * situations (see Mantis #1399) where (broken) + * HTTP implementations fail to supply values needed + * by the post processor (or other parts of the + * application). + *
+ * This function MUST only be called from within + * the MHD_AccessHandlerCallback (otherwise, access + * maybe improperly synchronized). Furthermore, + * the client must guarantee that the key and + * value arguments are 0-terminated strings that + * are NOT freed until the connection is closed. + * (The easiest way to do this is by passing only + * arguments to permanently allocated strings.). + * + * @param connection the connection for which a + * value should be set + * @param kind kind of the value + * @param key key for the value + * @param value the value itself + * @return MHD_NO if the operation could not be + * performed due to insufficient memory; + * MHD_YES on success + */ +int +MHD_set_connection_value (struct MHD_Connection *connection, + enum MHD_ValueKind kind, + const char *key, + const char *value); + /** * Get a particular header value. If multiple * values match the kind, return any one of them.