diff options
author | Xavier Roche <xroche@users.noreply.github.com> | 2013-04-14 17:52:28 +0000 |
---|---|---|
committer | Xavier Roche <xroche@users.noreply.github.com> | 2013-04-14 17:52:28 +0000 |
commit | 33d7070c48078979c1b9dbea983cd1a37299c16e (patch) | |
tree | 57b3b45fe99d4d443ed03c0ed8b8e4daf8e4d889 /src | |
parent | 4ac6c95c49e7cd8e678555383d5390beadd84953 (diff) |
Do not force a 206 status (partial content) when we see a "Content-Range" response header, because some servers are weird
Fixes: issue 7
Diffstat (limited to 'src')
-rw-r--r-- | src/htsback.c | 11 | ||||
-rw-r--r-- | src/htslib.c | 23 | ||||
-rw-r--r-- | src/htslib.h | 2 |
3 files changed, 29 insertions, 7 deletions
diff --git a/src/htsback.c b/src/htsback.c index 87df61e..a19d543 100644 --- a/src/htsback.c +++ b/src/htsback.c @@ -459,7 +459,8 @@ int back_finalize(httrackp* opt,cache_back* cache,struct_back* sback,int p) { /* Don't store broken files. Note: check is done before compression. If the file is partial, the next run will attempt to continue it with compression too. */ - if (back[p].r.totalsize > 0 && back[p].r.size != back[p].r.totalsize && ! opt->tolerant) { + if (back[p].r.totalsize > 0 && back[p].r.statuscode > 0 + && back[p].r.size != back[p].r.totalsize && ! opt->tolerant) { if (back[p].status == STATUS_READY) { if (opt->log!=NULL) { HTS_LOG(opt,LOG_WARNING); @@ -3218,8 +3219,12 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti // parfois les serveurs buggés renvoient un content-range avec un 200 if (back[i].r.statuscode==HTTP_OK) // 'OK' - if (strfield(rcvd,"content-range:")) // Avec un content-range: relisez les RFC.. - back[i].r.statuscode=206; // FORCER A 206 !!!!! + if (strfield(rcvd, "content-range:")) { // Avec un content-range: relisez les RFC.. + // Fake range (the file is complete) + if (!(back[i].r.crange_start == 0 && back[i].r.crange_end == back[i].r.crange - 1)) { + back[i].r.statuscode=HTTP_PARTIAL_CONTENT; // FORCER A 206 !!!!! + } + } } while(strnotempty(rcvd)); // ---------------------------------------- diff --git a/src/htslib.c b/src/htslib.c index 51ea004..1105900 100644 --- a/src/htslib.c +++ b/src/htslib.c @@ -1353,10 +1353,25 @@ void treathead(t_cookie* cookie,char* adr,char* fil,htsblk* retour,char* rcvd) { } } else if ((p=strfield(rcvd,"Content-Range:"))!=0) { - char* a=strstr(rcvd+p,"*/"); - if (a) { - if (sscanf(a+2,LLintP,&retour->crange) != 1) { - retour->crange=0; + // Content-Range: bytes 0-70870/70871 + char* a; + for(a = rcvd+p ; is_space(*a) ; a++) ; + if (strncasecmp(a, "bytes ", 6) == 0) { + for(a += 6 ; is_space(*a) ; a++) ; + if (sscanf(a, LLintP "-" LLintP "/" LLintP, &retour->crange_start, &retour->crange_end, &retour->crange) != 3) { + retour->crange_start = 0; + retour->crange_end = 0; + retour->crange = 0; + a = strchr(rcvd+p, '/'); + if (a != NULL) { + a++; + if (sscanf(a,LLintP,&retour->crange) == 1) { + retour->crange_start = 0; + retour->crange_end = retour->crange - 1; + } else { + retour->crange=0; + } + } } } } diff --git a/src/htslib.h b/src/htslib.h index 5871c8d..d59ee6d 100644 --- a/src/htslib.h +++ b/src/htslib.h @@ -167,6 +167,8 @@ struct htsblk { char etag[64]; // Etag char cdispo[256]; // Content-Disposition coupé LLint crange; // Content-Range + LLint crange_start; // Content-Range + LLint crange_end; // Content-Range int debugid; // debug connection /* */ htsrequest req; // paramètres pour la requête |