Skip to content

Add function to pass libmicrohttpd options when starting Prometheus listener #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions promhttp/include/promhttp.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,16 @@ void promhttp_set_active_collector_registry(prom_collector_registry_t *active_re
*/
struct MHD_Daemon *promhttp_start_daemon(unsigned int flags, unsigned short port, MHD_AcceptPolicyCallback apc,
void *apc_cls);

/**
* @brief Starts a daemon in the background and returns a pointer to an MHD_Daemon.
*
* This is the same as promhttp_start_daemon(), except it allows applications
* to pass options to MHD_start_daemon() directly.
*
* @return struct MHD_Daemon*
*/
struct MHD_Daemon *promhttp_start_daemon_with_options(unsigned int flags, unsigned short port,
MHD_AcceptPolicyCallback apc,
void *apc_cls, ...);

20 changes: 20 additions & 0 deletions promhttp/src/promhttp.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#include <string.h>
#include <stdarg.h>

#include "microhttpd.h"
#include "prom.h"
Expand Down Expand Up @@ -63,3 +64,22 @@ struct MHD_Daemon *promhttp_start_daemon(unsigned int flags, unsigned short port
void *apc_cls) {
return MHD_start_daemon(flags, port, apc, apc_cls, &promhttp_handler, NULL, MHD_OPTION_END);
}

static struct MHD_Daemon *promhttp_start_daemon_with_options_va(unsigned int flags, unsigned short port,
MHD_AcceptPolicyCallback apc,
void *apc_cls, va_list ap) {
return MHD_start_daemon_va(flags, port, apc, apc_cls, &promhttp_handler, NULL, ap);
}

struct MHD_Daemon *promhttp_start_daemon_with_options(unsigned int flags, unsigned short port,
MHD_AcceptPolicyCallback apc,
void *apc_cls, ...) {
va_list ap;
struct MHD_Daemon *ret;

va_start(ap, apc_cls);
ret = promhttp_start_daemon_with_options_va(flags, port, apc, apc_cls, ap);
va_end(ap);

return ret;
}