From ba57509461fb1e1819ecfe037b8d88b9257627fc Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Sat, 19 Dec 2020 13:17:30 +0100 Subject: [PATCH] Bugfix for redirection --- src/client.c | 11 ++++++++--- src/uri.c | 4 +++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/client.c b/src/client.c index e38e790..b58de8f 100644 --- a/src/client.c +++ b/src/client.c @@ -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; } diff --git a/src/uri.c b/src/uri.c index 3f0d57f..ef68e0c 100644 --- a/src/uri.c +++ b/src/uri.c @@ -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);