Skip to content
Open
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
6 changes: 6 additions & 0 deletions promhttp/src/promhttp.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "microhttpd.h"
#include "prom.h"

#define MIMETYPE_TEXT_PLAIN "text/plain; version=0.0.4; charset=utf-8"

prom_collector_registry_t *PROM_ACTIVE_REGISTRY;

void promhttp_set_active_collector_registry(prom_collector_registry_t *active_registry) {
Expand All @@ -34,26 +36,30 @@ int promhttp_handler(void *cls, struct MHD_Connection *connection, const char *u
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);
MHD_add_response_header (response, "Content-Type", MIMETYPE_TEXT_PLAIN);
int 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);
MHD_add_response_header (response, "Content-Type", MIMETYPE_TEXT_PLAIN);
int 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);
MHD_add_response_header (response, "Content-Type", MIMETYPE_TEXT_PLAIN);
int 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);
MHD_add_response_header (response, "Content-Type", MIMETYPE_TEXT_PLAIN);
int ret = MHD_queue_response(connection, MHD_HTTP_BAD_REQUEST, response);
MHD_destroy_response(response);
return ret;
Expand Down