diff options
author | Patrick Steinhardt <ps@pks.im> | 2020-01-06 11:53:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-06 11:53:53 +0100 |
commit | 33f93bf345b606cb850d251653bffdf6808033eb (patch) | |
tree | eb14b7f136c77cbcbf25dcddf1e2b605633def20 | |
parent | f51735973b36799b10a039b6e61ff844cae7c0d2 (diff) | |
parent | 05c1fb8a593c6aeb3869822ccc5cd551ba56d87f (diff) | |
download | libgit2-33f93bf345b606cb850d251653bffdf6808033eb.tar.gz |
Merge pull request #5325 from josharian/no-double-slash
http: avoid generating double slashes in url
-rw-r--r-- | src/transports/http.c | 8 | ||||
-rw-r--r-- | src/transports/winhttp.c | 6 |
2 files changed, 11 insertions, 3 deletions
diff --git a/src/transports/http.c b/src/transports/http.c index 47094f700..b581d6f69 100644 --- a/src/transports/http.c +++ b/src/transports/http.c @@ -183,7 +183,11 @@ static int gen_request( { http_subtransport *t = OWNING_SUBTRANSPORT(s); const char *path = t->server.url.path ? t->server.url.path : "/"; + const char *service_url = s->service_url; size_t i; + /* If path already ends in /, remove the leading slash from service_url */ + if ((git__suffixcmp(path, "/") == 0) && (git__prefixcmp(service_url, "/") == 0)) + service_url++; if (t->proxy_opts.type == GIT_PROXY_SPECIFIED) git_buf_printf(buf, "%s %s://%s:%s%s%s HTTP/1.1\r\n", @@ -191,10 +195,10 @@ static int gen_request( t->server.url.scheme, t->server.url.host, t->server.url.port, - path, s->service_url); + path, service_url); else git_buf_printf(buf, "%s %s%s HTTP/1.1\r\n", - s->verb, path, s->service_url); + s->verb, path, service_url); git_buf_puts(buf, "User-Agent: "); git_http__user_agent(buf); diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c index 688b5369b..3a4497da5 100644 --- a/src/transports/winhttp.c +++ b/src/transports/winhttp.c @@ -373,11 +373,15 @@ static int winhttp_stream_connect(winhttp_stream *s) int default_connect_timeout = DEFAULT_CONNECT_TIMEOUT; DWORD autologon_policy = WINHTTP_AUTOLOGON_SECURITY_LEVEL_HIGH; + const char *service_url = s->service_url; size_t i; const git_proxy_options *proxy_opts; + /* If path already ends in /, remove the leading slash from service_url */ + if ((git__suffixcmp(t->server.url.path, "/") == 0) && (git__prefixcmp(service_url, "/") == 0)) + service_url++; /* Prepare URL */ - git_buf_printf(&buf, "%s%s", t->server.url.path, s->service_url); + git_buf_printf(&buf, "%s%s", t->server.url.path, service_url); if (git_buf_oom(&buf)) return -1; |