client refactor

This commit is contained in:
2021-01-06 19:10:06 +01:00
parent 6bbf79245b
commit ee6f9115a8

View File

@ -133,13 +133,7 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int
goto respond; goto respond;
} }
if (conf->type != CONFIG_TYPE_LOCAL) { if (conf->type == CONFIG_TYPE_LOCAL) {
print("Reverse proxy for %s:%i", conf->rev_proxy.hostname, conf->rev_proxy.port);
// TODO Reverse Proxy
res.status = http_get_status(501);
goto respond;
}
http_uri uri; http_uri uri;
ret = uri_init(&uri, conf->local.webroot, req.uri, conf->local.dir_mode); ret = uri_init(&uri, conf->local.webroot, req.uri, conf->local.dir_mode);
if (ret != 0) { if (ret != 0) {
@ -215,8 +209,8 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int
char *if_modified_since = http_get_header_field(&req.hdr, "If-Modified-Since"); char *if_modified_since = http_get_header_field(&req.hdr, "If-Modified-Since");
char *if_none_match = http_get_header_field(&req.hdr, "If-None-Match"); char *if_none_match = http_get_header_field(&req.hdr, "If-None-Match");
if ((if_none_match != NULL && strstr(if_none_match, uri.meta->etag) == NULL) || (accept_if_modified_since && if ((if_none_match != NULL && strstr(if_none_match, uri.meta->etag) == NULL) ||
if_modified_since != NULL && strcmp(if_modified_since, last_modified) == 0)) { (accept_if_modified_since && if_modified_since != NULL && strcmp(if_modified_since, last_modified) == 0)) {
res.status = http_get_status(304); res.status = http_get_status(304);
goto respond; goto respond;
} }
@ -266,7 +260,8 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int
} }
char *accept_encoding = http_get_header_field(&req.hdr, "Accept-Encoding"); char *accept_encoding = http_get_header_field(&req.hdr, "Accept-Encoding");
if (uri.meta->filename_comp[0] != 0 && accept_encoding != NULL && strstr(accept_encoding, "deflate") != NULL) { if (uri.meta->filename_comp[0] != 0 && accept_encoding != NULL &&
strstr(accept_encoding, "deflate") != NULL) {
file = fopen(uri.meta->filename_comp, "rb"); file = fopen(uri.meta->filename_comp, "rb");
if (file == NULL) { if (file == NULL) {
cache_filename_comp_invalid(uri.filename); cache_filename_comp_invalid(uri.filename);
@ -325,7 +320,7 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int
if (status != NULL) { if (status != NULL) {
res.status = http_get_status(strtoul(status, NULL, 10)); res.status = http_get_status(strtoul(status, NULL, 10));
http_remove_header_field(&res.hdr, "Status", HTTP_REMOVE_ALL); http_remove_header_field(&res.hdr, "Status", HTTP_REMOVE_ALL);
if (res.status == NULL){ if (res.status == NULL) {
res.status = http_get_status(500); res.status = http_get_status(500);
sprintf(err_msg, "The status code was set to an invalid or unknown value."); sprintf(err_msg, "The status code was set to an invalid or unknown value.");
goto respond; goto respond;
@ -342,7 +337,14 @@ int client_request_handler(sock *client, unsigned long client_num, unsigned int
if (http_get_header_field(&res.hdr, "Content-Length") == NULL) { if (http_get_header_field(&res.hdr, "Content-Length") == NULL) {
http_add_header_field(&res.hdr, "Transfer-Encoding", "chunked"); http_add_header_field(&res.hdr, "Transfer-Encoding", "chunked");
} }
}
} else if (conf->type != CONFIG_TYPE_LOCAL) {
print("Reverse proxy for %s:%i", conf->rev_proxy.hostname, conf->rev_proxy.port);
// TODO Reverse Proxy
res.status = http_get_status(501);
} else {
print(ERR_STR "Unknown host type: %i" CLR_STR, conf->type);
res.status = http_get_status(501);
} }
respond: respond: