commit 60ac05357c165b2b9aa4836616db21eeaa4211ea from: Stefan Sperling date: Sun Apr 28 20:54:45 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 - fe55fe41ebae13ff135eb0041f19a224015cbf29 commit + 60ac05357c165b2b9aa4836616db21eeaa4211ea blob - e6d3950b1c2fa7616f6a5e4df7e81874347259fe blob + 1ff020ff9eb02181df0c0c89dba5ac9e4a6cfc74 --- libexec/got-fetch-http/Makefile +++ libexec/got-fetch-http/Makefile @@ -3,7 +3,8 @@ .include "../../got-version.mk" PROG= got-fetch-http -SRCS= got-fetch-http.c bufio.c hash.c error.c inflate.c pkt.c pollfd.c +SRCS= got-fetch-http.c bufio.c hash.c error.c inflate.c pkt.c \ + pollfd.c path.c CPPFLAGS= -I${.CURDIR}/../../include -I${.CURDIR}/../../lib blob - a62f4f48f936f8cb6c39475cec6af2804c62e233 blob + 302be74ffa6969c1d5a365a2cf1e9e6de1c2bade --- libexec/got-fetch-http/got-fetch-http.c +++ libexec/got-fetch-http/got-fetch-http.c @@ -16,6 +16,7 @@ */ #include +#include #include #include @@ -30,6 +31,7 @@ #include #include "got_error.h" +#include "got_path.h" #include "got_version.h" #include "got_lib_pkt.h" @@ -159,17 +161,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"); @@ -346,7 +345,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; @@ -367,7 +365,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; @@ -445,7 +443,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; @@ -528,7 +526,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; @@ -575,6 +574,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");