libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

commit 198ce9d5339edc3b464e603b54c3837aeda8ccd7
parent 116ed97689509262adcb464302a382cbd37290a9
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 21 Dec 2025 16:06:46 +0100

implement MHD_http_method_to_string and MHD_protocol_version_to_string

Diffstat:
Msrc/include/microhttpd2.h | 10----------
Msrc/mhd2/Makefile.am | 3++-
Asrc/mhd2/mhd_const.c | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 99 insertions(+), 11 deletions(-)

diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h @@ -2572,16 +2572,6 @@ enum MHD_PredefinedHeader MHD_PREDEF_ACCEPT_LANGUAGE = 17 }; -/** - * Get text version of the predefined header. - * @param stk the code of the predefined header - * @return the pointer to the text version, - * NULL if method is MHD_HTTP_METHOD_OTHER - * or not known. - */ -MHD_EXTERN_ const struct MHD_String * -MHD_predef_header_to_string (enum MHD_PredefinedHeader stk) -MHD_FN_CONST_; /** @} */ /* end of group headers */ diff --git a/src/mhd2/Makefile.am b/src/mhd2/Makefile.am @@ -44,6 +44,7 @@ libmicrohttpd2_la_SOURCES = \ mhd_socket_error_funcs.c mhd_socket_error_funcs.h mhd_socket_error.h \ mhd_atomic_counter.c mhd_atomic_counter.h \ mhd_bool.h \ + mhd_const.c \ mhd_str.c mhd_str.h \ mhd_rng.c mhd_rng.h \ mhd_str_macros.h mhd_str_types.h \ @@ -270,7 +271,7 @@ tls_open_OPTSOURCES = \ tls_mbed_OPTSOURCES = \ tls_mbed_tls_lib.h tls_mbed_daemon_data.h tls_mbed_conn_data.h \ - tls_mbed_funcs.c tls_mbed_funcs.h + tls_mbed_funcs.c tls_mbed_funcs.h if MHD_SUPPORT_HTTP2 libmicrohttpd2_la_SOURCES += $(httptwo_OPTSOURCES) diff --git a/src/mhd2/mhd_const.c b/src/mhd2/mhd_const.c @@ -0,0 +1,97 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */ +/* + This file is part of GNU libmicrohttpd. + Copyright (C) 2025 Christian Grothoff + + GNU libmicrohttpd is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + GNU libmicrohttpd is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + Alternatively, you can redistribute GNU libmicrohttpd and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License, or (at your option) any later version, together + with the eCos exception, as follows: + + As a special exception, if other files instantiate templates or + use macros or inline functions from this file, or you compile this + file and link it with other works to produce a work based on this + file, this file does not by itself cause the resulting work to be + covered by the GNU General Public License. However the source code + for this file must still be made available in accordance with + section (3) of the GNU General Public License v2. + + This exception does not invalidate any other reasons why a work + based on this file might be covered by the GNU General Public + License. + + You should have received copies of the GNU Lesser General Public + License and the GNU General Public License along with this library; + if not, see <https://www.gnu.org/licenses/>. +*/ + +/** + * @file src/mhd2/mhd_const.c + * @brief convenience functions returning constant string values + * @author Christian Grothoff + */ + +#include "mhd_sys_options.h" + +#include <stdio.h> +#ifdef HAVE_STDLIB_H +# include <stdlib.h> +#elif defined(HAVE_UNISTD_H) +# include <unistd.h> +#endif +#include "sys_null_macro.h" +#include "mhd_public_api.h" + +#define CONST_STR(s) \ + { sizeof (s), s } + +MHD_EXTERN_ const struct MHD_String * +MHD_protocol_version_to_string (enum MHD_HTTP_ProtocolVersion pv) +{ + static const struct MHD_String results[] = { + CONST_STR ("invalid"), + CONST_STR ("HTTP/1.0"), + CONST_STR ("HTTP/1.2"), + CONST_STR ("HTTP/2"), + CONST_STR ("HTTP/3") + }; + + if ( (pv > 0) && + ((unsigned int) pv < sizeof (results) / sizeof(results[0])) ) + return &results[pv]; + return NULL; +} + + +MHD_EXTERN_ const struct MHD_String * +MHD_http_method_to_string (enum MHD_HTTP_Method method) +{ + static const struct MHD_String results[] = { + CONST_STR ("invalid"), + CONST_STR ("GET"), + CONST_STR ("HEAD"), + CONST_STR ("POST"), + CONST_STR ("PUT"), + CONST_STR ("DELETE"), + CONST_STR ("CONNECT"), + CONST_STR ("OPTIONS"), + CONST_STR ("TRACE"), + CONST_STR ("*") + }; + + if ( (method > 0) && + ((unsigned int) method < sizeof (results) / sizeof(results[0])) ) + return &results[method]; + return NULL; +}