Bugfix for redirection

This commit is contained in:
2020-12-19 13:17:30 +01:00
parent 4e079e094f
commit ba57509461
2 changed files with 11 additions and 4 deletions

View File

@ -136,12 +136,17 @@ int client_request_handler(sock *client, int req_num) {
ssize_t size = sizeof(buf0);
url_decode(req.uri, buf0, &size);
if (strcmp(uri.uri, buf0) != 0 || (strncmp(uri.uri, "/.well-known/", 13) != 0 && !client->enc)) {
int change_proto = strncmp(uri.uri, "/.well-known/", 13) != 0 && !client->enc;
if (strcmp(uri.uri, buf0) != 0 || change_proto) {
res.status = http_get_status(308);
size = sizeof(buf0);
encode_url(uri.uri, buf0, &size);
sprintf(buf1, "https://%s%s", host, buf0);
http_add_header_field(&res.hdr, "Location", buf1);
if (change_proto) {
sprintf(buf1, "https://%s%s", host, buf0);
http_add_header_field(&res.hdr, "Location", buf1);
} else {
http_add_header_field(&res.hdr, "Location", buf0);
}
goto respond;
}

View File

@ -68,9 +68,11 @@ int uri_init(http_uri *uri, const char *webroot, const char *uri_str, int dir_mo
uri->path = malloc(size);
uri->pathinfo = malloc(size);
strcpy(uri->path, uri->req_path);
strcpy(uri->pathinfo, "");
if (uri->path[strlen(uri->path) - 1] == '/') {
uri->path[strlen(uri->path) - 1] = 0;
strcpy(uri->pathinfo, "/");
} else {
strcpy(uri->pathinfo, "");
}
while (1) {
sprintf(buf0, "%s%s", uri->webroot, uri->path);