libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit f1f8851cd2c297d228617d5fc0f92be509ffe66a
parent 88b880e928f08ed3866739a1db93e57108e73f55
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed,  4 Aug 2021 18:58:55 +0200

introduce new MHD_CONNECTION_INFO_HTTP_STATUS

Diffstat:
MChangeLog | 3+++
Mdoc/libmicrohttpd.texi | 6++++++
Msrc/include/microhttpd.h | 20++++++++++++++++----
Msrc/microhttpd/connection.c | 8+++++++-
4 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,6 @@ +Wed 04 Aug 2021 06:56:52 PM CEST + Introduce new MHD_CONNECTION_INFO_HTTP_STATUS. -CG + Mon 26 Apr 2021 02:09:46 PM CEST Importing experimental Websocket support by David Gausmann. -CG diff --git a/doc/libmicrohttpd.texi b/doc/libmicrohttpd.texi @@ -3159,6 +3159,12 @@ to the access handler. Takes no extra arguments. +@index MHD_CONNECTION_INFO_HTTP_STATUS +Returns the HTTP status code of the response that was +queued. Returns NULL if no response was queued yet. + +Takes no extra arguments. + @end table @end deftp diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h @@ -1,6 +1,6 @@ /* This file is part of libmicrohttpd - Copyright (C) 2006--2020 Christian Grothoff (and other contributing authors) + Copyright (C) 2006-2021 Christian Grothoff (and other contributing authors) Copyright (C) 2015-2021 Evgeny Grin (Karlson2k) This library is free software; you can redistribute it and/or @@ -131,7 +131,7 @@ typedef intptr_t ssize_t; * they are parsed as decimal numbers. * Example: 0x01093001 = 1.9.30-1. */ -#define MHD_VERSION 0x00097302 +#define MHD_VERSION 0x00097303 #ifdef __has_attribute @@ -139,7 +139,7 @@ typedef intptr_t ssize_t; #define _MHD_FLAGS_ENUM __attribute__((flag_enum)) #endif /* flag_enum */ #if __has_attribute (enum_extensibility) -#define _MHD_FIXED_ENUM __attribute__((enum_extensibility(closed))) +#define _MHD_FIXED_ENUM __attribute__((enum_extensibility (closed))) #endif /* enum_extensibility */ #endif /* __has_attribute */ @@ -1981,6 +1981,11 @@ union MHD_ConnectionInfo unsigned int connection_timeout; /** + * HTTP status queued with the response, for #MHD_CONNECTION_INFO_HTTP_STATUS. + */ + unsigned int http_status; + + /** * Connect socket */ MHD_socket connect_fd; @@ -2121,7 +2126,14 @@ enum MHD_ConnectionInfoType * Return length of the client's HTTP request header. * @ingroup request */ - MHD_CONNECTION_INFO_REQUEST_HEADER_SIZE + MHD_CONNECTION_INFO_REQUEST_HEADER_SIZE, + + /** + * Return HTTP status queued with the response. NULL + * if no HTTP response has been queued yet. + */ + MHD_CONNECTION_INFO_HTTP_STATUS + } _MHD_FIXED_ENUM; diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -1389,6 +1389,7 @@ connection_shrink_read_buffer (struct MHD_Connection *connection) new_buf = MHD_pool_reallocate (c->pool, c->read_buffer, c->read_buffer_size, c->read_buffer_offset); mhd_assert (c->read_buffer == new_buf); + (void) new_buf; /* squash compiler warning */ c->read_buffer_size = c->read_buffer_offset; if (0 == c->read_buffer_size) c->read_buffer = NULL; @@ -1463,6 +1464,7 @@ connection_shrink_write_buffer (struct MHD_Connection *connection) new_buf = MHD_pool_reallocate (pool, c->write_buffer, c->write_buffer_size, c->write_buffer_append_offset); mhd_assert (c->write_buffer == new_buf); + (void) new_buf; /* squash compiler warning */ c->write_buffer_size = c->write_buffer_append_offset; } @@ -2008,7 +2010,7 @@ transmit_error_response_len (struct MHD_Connection *connection, * Transmit static string as error response */ #define transmit_error_response_static(c, code, msg) \ - transmit_error_response_len (c, code, msg, MHD_STATICSTR_LEN_(msg)) + transmit_error_response_len (c, code, msg, MHD_STATICSTR_LEN_ (msg)) /** * Update the 'event_loop_info' field of this connection based on the state @@ -4443,6 +4445,10 @@ MHD_get_connection_info (struct MHD_Connection *connection, (MHD_CONNECTION_CLOSED == connection->state) ) return NULL; /* invalid, too early! */ return (const union MHD_ConnectionInfo *) &connection->header_size; + case MHD_CONNECTION_INFO_HTTP_STATUS: + if (NULL == connection->response) + return NULL; + return (const union MHD_ConnectionInfo *) &connection->responseCode; default: return NULL; }