diff options
author | Michael Forney <mforney@mforney.org> | 2022-03-17 01:41:09 +0000 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2022-03-17 01:41:09 +0000 |
commit | 8bd5be7c707b979caa277637cadf356b78c2edb5 (patch) | |
tree | 64be81d76e5dcdd0f9f4b9c72e38b970d008ef10 /sys/src/cmd/git | |
parent | 2e47badb88312c5c045a8042dc2ef80148e5ab47 (diff) |
git/fetch: improve detection of dumb http protocol
If the server only supports the dumb protocol, the first 4 bytes of
response will be the initial part of the hash of the first ref.
The http-protocol documentation says that we should fall back to the
dumb protocol when we don't see a content-type of
application/x-$servicename-advertisement. Check this before
attempting to read a smart git packet.
Diffstat (limited to 'sys/src/cmd/git')
-rw-r--r-- | sys/src/cmd/git/proto.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/sys/src/cmd/git/proto.c b/sys/src/cmd/git/proto.c index 1611a2abe..05d72cc49 100644 --- a/sys/src/cmd/git/proto.c +++ b/sys/src/cmd/git/proto.c @@ -220,14 +220,27 @@ static int issmarthttp(Conn *c, char *direction) { char buf[Pktmax+1], svc[128]; - int n; + int fd, n; + + if((fd = webopen(c, "contenttype", OREAD)) == -1) + return -1; + n = readn(fd, buf, sizeof(buf) - 1); + close(fd); + if(n == -1) + return -1; + buf[n] = '\0'; + snprint(svc, sizeof(svc), "application/x-git-%s-pack-advertisement", direction); + if(strcmp(svc, buf) != 0){ + werrstr("dumb http protocol not supported"); + return -1; + } if((n = readpkt(c, buf, sizeof(buf))) == -1) sysfatal("http read: %r"); buf[n] = 0; snprint(svc, sizeof(svc), "# service=git-%s-pack\n", direction); if(strncmp(svc, buf, n) != 0){ - werrstr("dumb http protocol not supported"); + werrstr("invalid initial packet line"); return -1; } if(readpkt(c, buf, sizeof(buf)) != 0){ |