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.
This commit is contained in:
parent
2e47badb88
commit
8bd5be7c70
1 changed files with 15 additions and 2 deletions
|
@ -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){
|
||||
|
|
Loading…
Reference in a new issue