commit f571fea2849dfbb5568180ac8140282f5bc6b351 from: Stefan Sperling via: Thomas Adam date: Mon Apr 29 12:23:39 2024 UTC redo "got-fetch-http: fix GET request URL", without breaking tests My previous fix for ~user in SSH URLs broke ~user in HTTP URLs, as used on sourcehut. Sanitize the amount of leading and embedded slashes in URLs to make things work in all cases. The root cause of the test problem with naddy's previous diff was likely in the http-server script itself, where a request like GET //repo//info/refs?service=git-upload-pack somehow ended up as GET $testroot///info/refs. We work around this here by avoiding the double slashes. commit - c7d1a4d98cf513b3015d80f6948b25aad5929a17 commit + f571fea2849dfbb5568180ac8140282f5bc6b351 blob - 43858a3fc70b77963b5985f1bf6470bb24429296 blob + 141ea5ab9f3b8b1b2767cb4e947d7065f387b0f2 --- libexec/got-fetch-http/got-fetch-http.c +++ libexec/got-fetch-http/got-fetch-http.c @@ -18,6 +18,7 @@ #include "got_compat.h" #include +#include #include #include @@ -32,6 +33,7 @@ #include #include "got_error.h" +#include "got_path.h" #include "got_version.h" #include "got_lib_pkt.h" @@ -161,17 +163,14 @@ http_open(struct bufio *bio, int https, const char *me char *p, *req; int r; - if (path_sufx != NULL && *path && path[strlen(path) - 1] == '/') - path_sufx++; /* skip the slash */ - if (strcmp(method, "POST") == 0) te = "\r\nTransfer-Encoding: chunked\r\n"; if (ctype) chdr = "Content-Type: "; - r = asprintf(&p, "%s/%s%s%s", path, path_sufx, - query ? "?" : "", query ? query : ""); + r = asprintf(&p, "%s%s/%s%s%s", got_path_is_absolute(path) ? "" :"/", + path, path_sufx, query ? "?" : "", query ? query : ""); if (r == -1) err(1, "asprintf"); @@ -348,7 +347,6 @@ get_refs(int https, const char *host, const char *port struct bufio bio; char buf[GOT_PKT_MAX]; const struct got_error *e; - const char *sufx = "/info/refs"; size_t chunksz = 0; ssize_t r; int skip; @@ -369,7 +367,7 @@ get_refs(int https, const char *host, const char *port goto err; } - if (http_open(&bio, https, "GET", host, port, path, sufx, + if (http_open(&bio, https, "GET", host, port, path, "info/refs", "service=git-upload-pack", NULL) == -1) goto err; @@ -447,7 +445,7 @@ upload_request(int https, const char *host, const char if (pledge("stdio", NULL) == -1) err(1, "pledge"); #endif - if (http_open(&bio, https, "POST", host, port, path, "/git-upload-pack", + if (http_open(&bio, https, "POST", host, port, path, "git-upload-pack", NULL, UPLOAD_PACK_REQ) == -1) goto err; @@ -530,7 +528,8 @@ int main(int argc, char **argv) { struct pollfd pfd; - const char *host, *port, *path; + const char *host, *port; + char *path; int https = 0; int ch; @@ -577,6 +576,7 @@ main(int argc, char **argv) host = argv[1]; port = argv[2]; path = argv[3]; + got_path_strip_trailing_slashes(path); if (get_refs(https, host, port, path) == -1) errx(1, "failed to get refs");