--- a/promhttp/src/promhttp.c +++ b/promhttp/src/promhttp.c @@ -21,6 +21,13 @@ prom_collector_registry_t *PROM_ACTIVE_REGISTRY; +/* libmicrohttpd >= 0.9.71 declares the handler return type as enum MHD_Result */ +#if MHD_VERSION >= 0x00097100 +typedef enum MHD_Result promhttp_result_t; +#else +typedef int promhttp_result_t; +#endif + void promhttp_set_active_collector_registry(prom_collector_registry_t *active_registry) { if (!active_registry) { PROM_ACTIVE_REGISTRY = PROM_COLLECTOR_REGISTRY_DEFAULT; @@ -29,32 +36,32 @@ } } -int promhttp_handler(void *cls, struct MHD_Connection *connection, const char *url, const char *method, - const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) { +promhttp_result_t promhttp_handler(void *cls, struct MHD_Connection *connection, const char *url, const char *method, + const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) { if (strcmp(method, "GET") != 0) { char *buf = "Invalid HTTP Method\n"; struct MHD_Response *response = MHD_create_response_from_buffer(strlen(buf), (void *)buf, MHD_RESPMEM_PERSISTENT); - int ret = MHD_queue_response(connection, MHD_HTTP_BAD_REQUEST, response); + promhttp_result_t ret = MHD_queue_response(connection, MHD_HTTP_BAD_REQUEST, response); MHD_destroy_response(response); return ret; } if (strcmp(url, "/") == 0) { char *buf = "OK\n"; struct MHD_Response *response = MHD_create_response_from_buffer(strlen(buf), (void *)buf, MHD_RESPMEM_PERSISTENT); - int ret = MHD_queue_response(connection, MHD_HTTP_OK, response); + promhttp_result_t ret = MHD_queue_response(connection, MHD_HTTP_OK, response); MHD_destroy_response(response); return ret; } if (strcmp(url, "/metrics") == 0) { const char *buf = prom_collector_registry_bridge(PROM_ACTIVE_REGISTRY); struct MHD_Response *response = MHD_create_response_from_buffer(strlen(buf), (void *)buf, MHD_RESPMEM_MUST_FREE); - int ret = MHD_queue_response(connection, MHD_HTTP_OK, response); + promhttp_result_t ret = MHD_queue_response(connection, MHD_HTTP_OK, response); MHD_destroy_response(response); return ret; } char *buf = "Bad Request\n"; struct MHD_Response *response = MHD_create_response_from_buffer(strlen(buf), (void *)buf, MHD_RESPMEM_PERSISTENT); - int ret = MHD_queue_response(connection, MHD_HTTP_BAD_REQUEST, response); + promhttp_result_t ret = MHD_queue_response(connection, MHD_HTTP_BAD_REQUEST, response); MHD_destroy_response(response); return ret; }