Skip to content

Commit 3057ded

Browse files
Grégoire Barbiergitster
authored andcommitted
http-push and http-fetch: handle URLs without trailing /
The URL to a repository http-push and http-fetch takes should have a trailing slash. Instead of failing the request, add it ourselves before attempting such a request. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 325ce39 commit 3057ded

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

builtin-http-fetch.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ int cmd_http_fetch(int argc, const char **argv, const char *prefix)
99
const char **write_ref = NULL;
1010
char **commit_id;
1111
const char *url;
12+
char *rewritten_url = NULL;
1213
int arg = 1;
1314
int rc = 0;
1415
int get_tree = 0;
@@ -51,6 +52,12 @@ int cmd_http_fetch(int argc, const char **argv, const char *prefix)
5152
commits = 1;
5253
}
5354
url = argv[arg];
55+
if (url && url[strlen(url)-1] != '/') {
56+
rewritten_url = malloc(strlen(url)+2);
57+
strcpy(rewritten_url, url);
58+
strcat(rewritten_url, "/");
59+
url = rewritten_url;
60+
}
5461

5562
walker = get_http_walker(url);
5663
walker->get_tree = get_tree;
@@ -73,5 +80,8 @@ int cmd_http_fetch(int argc, const char **argv, const char *prefix)
7380

7481
walker_free(walker);
7582

83+
if (rewritten_url)
84+
free(rewritten_url);
85+
7686
return rc;
7787
}

http-push.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,6 +2169,7 @@ int main(int argc, char **argv)
21692169
int i;
21702170
int new_refs;
21712171
struct ref *ref;
2172+
char *rewritten_url = NULL;
21722173

21732174
setup_git_directory();
21742175

@@ -2236,6 +2237,14 @@ int main(int argc, char **argv)
22362237

22372238
no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
22382239

2240+
if (remote->url && remote->url[strlen(remote->url)-1] != '/') {
2241+
rewritten_url = malloc(strlen(remote->url)+2);
2242+
strcpy(rewritten_url, remote->url);
2243+
strcat(rewritten_url, "/");
2244+
remote->url = rewritten_url;
2245+
++remote->path_len;
2246+
}
2247+
22392248
/* Verify DAV compliance/lock support */
22402249
if (!locking_available()) {
22412250
rc = 1;
@@ -2416,6 +2425,8 @@ int main(int argc, char **argv)
24162425
}
24172426

24182427
cleanup:
2428+
if (rewritten_url)
2429+
free(rewritten_url);
24192430
if (info_ref_lock)
24202431
unlock_remote(info_ref_lock);
24212432
free(remote);

0 commit comments

Comments
 (0)