client refactor
This commit is contained in:
24
src/client.c
24
src/client.c
@ -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);
|
||||||
@ -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:
|
||||||
|
Reference in New Issue
Block a user