Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit 8115904

Browse files
committed
Check header for post request
1 parent a49ee55 commit 8115904

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

accelerator/server.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,20 @@ int main(int, char const**) {
119119
.post([&](served::response& res, const served::request& req) {
120120
char* json_result;
121121

122-
api_send_transfer(&service, req.body().c_str(), &json_result);
123-
res.set_header("content-type", "application/json");
122+
if (req.header("content-type") != "application/json") {
123+
cJSON* json_obj = cJSON_CreateObject();
124+
cJSON_AddStringToObject(json_obj, "message",
125+
"Invalid request header");
126+
json_result = cJSON_PrintUnformatted(json_obj);
127+
128+
res.set_status(SC_BAD_REQUEST);
129+
res.set_header("content-type", "application/json");
130+
cJSON_Delete(json_obj);
131+
} else {
132+
api_send_transfer(&service, req.body().c_str(), &json_result);
133+
res.set_header("content-type", "application/json");
134+
}
135+
124136
res << json_result;
125137
});
126138

0 commit comments

Comments
 (0)