diff --git a/pull/src/handler.cc b/pull/src/handler.cc index 83eb19ea..cec37f33 100644 --- a/pull/src/handler.cc +++ b/pull/src/handler.cc @@ -96,7 +96,7 @@ static std::size_t WriteResponse(struct mg_connection* conn, const std::string& body) { mg_printf(conn, "HTTP/1.1 200 OK\r\n" - "Content-Type: text/plain\r\n"); + "Content-Type: text/plain; charset=utf-8\r\n"); #ifdef HAVE_ZLIB auto acceptsGzip = IsEncodingAccepted(conn, "gzip"); diff --git a/pull/tests/integration/integration_test.cc b/pull/tests/integration/integration_test.cc index 49c79176..0ac4fd99 100644 --- a/pull/tests/integration/integration_test.cc +++ b/pull/tests/integration/integration_test.cc @@ -31,6 +31,7 @@ class IntegrationTest : public testing::Test { struct Resonse { long code = 0; std::string body; + std::string contentType; }; std::function fetchPrePerform_; @@ -59,6 +60,12 @@ class IntegrationTest : public testing::Test { curl_easy_getinfo(curl.get(), CURLINFO_RESPONSE_CODE, &response.code); + char* ct = nullptr; + curl_easy_getinfo(curl.get(), CURLINFO_CONTENT_TYPE, &ct); + if (ct) { + response.contentType = ct; + } + return response; } @@ -225,5 +232,17 @@ TEST_F(IntegrationTest, shouldDealWithExpiredCollectables) { EXPECT_THAT(metrics.body, Not(HasSubstr(second_counter_name))); } +TEST_F(IntegrationTest, shouldSendBodyAsUtf8) { + const std::string counter_name = "example_total"; + auto registry = RegisterSomeCounter(counter_name, default_metrics_path_); + + const auto metrics = FetchMetrics(default_metrics_path_); + + // check content type + + ASSERT_EQ(metrics.code, 200); + EXPECT_THAT(metrics.contentType, HasSubstr("utf-8")); +} + } // namespace } // namespace prometheus