From 8bd5be7c707b979caa277637cadf356b78c2edb5 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Thu, 17 Mar 2022 01:41:09 +0000 Subject: [PATCH] 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. --- sys/src/cmd/git/proto.c | 17 +++++++++++++++-- 1 file 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){