Set Content-Type

This commit is contained in:
blank X 2022-01-17 16:52:13 +07:00
parent 466115bc39
commit 2be821f324
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
4 changed files with 11 additions and 0 deletions

View File

@ -4,6 +4,7 @@
#include "404.hpp" #include "404.hpp"
int not_found(struct http_request* req) { int not_found(struct http_request* req) {
http_response_header(req, "Content-Type", "text/html");
http_response(req, 404, asset_404_html, asset_len_404_html); http_response(req, 404, asset_404_html, asset_len_404_html);
return KORE_RESULT_OK; return KORE_RESULT_OK;
} }

View File

@ -50,6 +50,7 @@ static bool send_hget_and_http_resp(struct http_request* req, const char* id, bo
error = "404: album not found"; error = "404: album not found";
} }
std::string error_page = build_error_page(error); std::string error_page = build_error_page(error);
http_response_header(req, "Content-Type", "text/html");
http_response(req, 404, error_page.c_str(), error_page.length()); http_response(req, 404, error_page.c_str(), error_page.length());
return true; return true;
} }
@ -91,6 +92,7 @@ static int album_or_image_start(struct http_request* req) {
http_state_cleanup(req); http_state_cleanup(req);
kore_log(LOG_ERR, "failed to initialize curl client"); kore_log(LOG_ERR, "failed to initialize curl client");
std::string error_page = build_error_page("Failed to initialize curl client"); std::string error_page = build_error_page("Failed to initialize curl client");
http_response_header(req, "Content-Type", "text/html");
http_response(req, 500, error_page.c_str(), error_page.length()); http_response(req, 500, error_page.c_str(), error_page.length());
return HTTP_STATE_COMPLETE; return HTTP_STATE_COMPLETE;
} }
@ -139,6 +141,7 @@ static int album_or_image_end(struct http_request* req) {
kore_curl_cleanup(client); kore_curl_cleanup(client);
http_state_cleanup(req); http_state_cleanup(req);
std::string error_page = build_error_page(error.c_str()); std::string error_page = build_error_page(error.c_str());
http_response_header(req, "Content-Type", "text/html");
http_response(req, 500, error_page.c_str(), error_page.length()); http_response(req, 500, error_page.c_str(), error_page.length());
return HTTP_STATE_COMPLETE; return HTTP_STATE_COMPLETE;
} }
@ -153,6 +156,7 @@ static int album_or_image_end(struct http_request* req) {
kore_curl_cleanup(client); kore_curl_cleanup(client);
http_state_cleanup(req); http_state_cleanup(req);
std::string error_page = build_error_page(error.c_str()); std::string error_page = build_error_page(error.c_str());
http_response_header(req, "Content-Type", "text/html");
http_response(req, 500, error_page.c_str(), error_page.length()); http_response(req, 500, error_page.c_str(), error_page.length());
return HTTP_STATE_COMPLETE; return HTTP_STATE_COMPLETE;
} }
@ -174,6 +178,7 @@ static int album_or_image_end(struct http_request* req) {
send_hset(id, is_album, ""); send_hset(id, is_album, "");
} }
std::string error_page = build_error_page(error.c_str()); std::string error_page = build_error_page(error.c_str());
http_response_header(req, "Content-Type", "text/html");
http_response(req, 404, error_page.c_str(), error_page.length()); http_response(req, 404, error_page.c_str(), error_page.length());
return HTTP_STATE_COMPLETE; return HTTP_STATE_COMPLETE;
} }
@ -208,6 +213,7 @@ static int album_or_image_end(struct http_request* req) {
kore_curl_cleanup(client); kore_curl_cleanup(client);
http_state_cleanup(req); http_state_cleanup(req);
std::string error_page = build_error_page(error.c_str(), true); std::string error_page = build_error_page(error.c_str(), true);
http_response_header(req, "Content-Type", "text/html");
http_response(req, 500, error_page.c_str(), error_page.length()); http_response(req, 500, error_page.c_str(), error_page.length());
return HTTP_STATE_COMPLETE; return HTTP_STATE_COMPLETE;
} }
@ -219,6 +225,7 @@ static int album_or_image_end(struct http_request* req) {
if (error) { if (error) {
kore_log(LOG_ERR, "%s", (*error).c_str()); kore_log(LOG_ERR, "%s", (*error).c_str());
std::string error_page = build_error_page((*error).c_str()); std::string error_page = build_error_page((*error).c_str());
http_response_header(req, "Content-Type", "text/html");
http_response(req, 500, error_page.c_str(), error_page.length()); http_response(req, 500, error_page.c_str(), error_page.length());
return HTTP_STATE_COMPLETE; return HTTP_STATE_COMPLETE;
} }

View File

@ -30,6 +30,7 @@ static int proxy_start(struct http_request* req) {
http_state_cleanup(req); http_state_cleanup(req);
kore_log(LOG_ERR, "failed to initialize curl client"); kore_log(LOG_ERR, "failed to initialize curl client");
std::string error_page = build_error_page("Failed to initialize curl client"); std::string error_page = build_error_page("Failed to initialize curl client");
http_response_header(req, "Content-Type", "text/html");
http_response(req, 500, error_page.c_str(), error_page.length()); http_response(req, 500, error_page.c_str(), error_page.length());
return HTTP_STATE_COMPLETE; return HTTP_STATE_COMPLETE;
} }
@ -69,6 +70,7 @@ static int proxy_end(struct http_request* req) {
kore_curl_cleanup(client); kore_curl_cleanup(client);
http_state_cleanup(req); http_state_cleanup(req);
std::string error_page = build_error_page(error.c_str()); std::string error_page = build_error_page(error.c_str());
http_response_header(req, "Content-Type", "text/html");
http_response(req, 500, error_page.c_str(), error_page.length()); http_response(req, 500, error_page.c_str(), error_page.length());
return HTTP_STATE_COMPLETE; return HTTP_STATE_COMPLETE;
} }

View File

@ -396,6 +396,7 @@ int send_album_page(struct http_request* req, Album album) {
} }
} }
response.append(ALBUM_PAGE_END); response.append(ALBUM_PAGE_END);
http_response_header(req, "Content-Type", "text/html");
http_response(req, 200, response.c_str(), response.length()); http_response(req, 200, response.c_str(), response.length());
return HTTP_STATE_COMPLETE; return HTTP_STATE_COMPLETE;
} }