I am working on a reverse-proxy server, using the crow framework in C++. I want to set the headers that i get after fetching the original server but it does not work. I receive 9 headers from original server but only 4 are added to current headers.
CROW_CATCHALL_ROUTE(Server)([](const crow::request& req, crow::response& res) {
string ip = get_server_ip(REQUEST_COUNT, IP_POOL);
auto op = fetch_response_from_ip(ip, req.raw_url, PORT);
if (op) {
res.code = op->status;
res.body = op->body;
if (req.raw_url != "/") {
for (const auto& header : op->headers) {
//std::cout << "Header: " << header.first << ": " << header.second << std::endl;
res.set_header(header.first, header.second);
}
}
// All headers set in the response are being logged correctly but they are not present when checked in the networks tab in dev tools
// and file contents are missing. I recive 9 headers from original server but only 4 are added to current headers 😢
std::cout << "Headers set in response:" << std::endl;
for (const auto& header : res.headers) {
std::cout << header.first << ": " << header.second << std::endl;
}
}
else {
res.code = 502; // Bad Gateway
res.write("Failed to forward request: Unexpected Error Occurred !");
}
res.set_header("BODY", op->body);
cout << endl << "BODY: === " << endl << op->body << endl;
res.end();
});
I am looping through all the received headers and setting them for my new Response, just to ensure they are set, i log them as well and it works fine but the headers are not added to the response. All files received are empty.
New contributor
axnjr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.