@@ -105,6 +105,8 @@ class AdminService {
105105 pjs::Object* respond_metrics (const stats::MetricData &metric_data);
106106 pjs::Object* respond_metrics (const stats::MetricDataSum &metric_data_sum);
107107
108+ pjs::Ref<http::ResponseHead> response_head (int status, const char *content_type = nullptr );
109+
108110 static const std::string s_path_log;
109111 static const std::string s_path_dump;
110112 static const std::string s_path_metrics;
@@ -207,7 +209,6 @@ void AdminService::open(const std::string &ip, int port, WorkerManager *wm) {
207209 return promise;
208210 } else if (path == s_path_metrics) {
209211 auto promise = pjs::Promise::make ();
210- auto metric_data = new stats::MetricData;
211212 wm->stats ([=](stats::MetricDataSum &metric_data) {
212213 InputContext ic;
213214 promise->settle (true , respond_metrics (metric_data));
@@ -233,9 +234,7 @@ int AdminService::open(const std::string &ip, int port, const std::function<pjs:
233234 if (res) {
234235 ret.set (res);
235236 } else {
236- auto head = http::ResponseHead::make ();
237- head->status = 404 ;
238- ret.set (Message::make (head, nullptr ));
237+ ret.set (Message::make (response_head (404 ), nullptr ));
239238 }
240239 }
241240 )),
@@ -346,7 +345,7 @@ pjs::Object* AdminService::respond_metrics(const stats::MetricData &metric_data)
346345 db.push (str, len);
347346 });
348347 db.flush ();
349- return Message::make (Data::make (std::move (buf)));
348+ return Message::make (response_head ( 200 , " text/plain " ), Data::make (std::move (buf)));
350349}
351350
352351pjs::Object* AdminService::respond_metrics (const stats::MetricDataSum &metric_data_sum) {
@@ -356,7 +355,18 @@ pjs::Object* AdminService::respond_metrics(const stats::MetricDataSum &metric_da
356355 db.push (str, len);
357356 });
358357 db.flush ();
359- return Message::make (Data::make (std::move (buf)));
358+ return Message::make (response_head (200 , " text/plain" ), Data::make (std::move (buf)));
359+ }
360+
361+ pjs::Ref<http::ResponseHead> AdminService::response_head (int status, const char *content_type) {
362+ auto head = http::ResponseHead::make ();
363+ head->status = status;
364+ if (content_type) {
365+ auto headers = pjs::Object::make ();
366+ headers->set (" content-type" , content_type);
367+ head->headers = headers;
368+ }
369+ return head;
360370}
361371
362372//
0 commit comments