From d92eda101b526dc52a1e1687458e958f2d892639 Mon Sep 17 00:00:00 2001 From: Micah Cowan Date: Thu, 31 Jan 2008 02:01:00 -0800 Subject: [PATCH] Properly handle missing Content-Length for partial HTTP fetches. --- src/ChangeLog | 7 +++++++ src/http.c | 17 +++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index fe1c8075..ea07167b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2008-01-31 Micah Cowan + + * http.c (gethttp): Don't derive hs->contlen from possibly + invalid/missing Content-Length; instead, get the appropriate + value from the Content-Range header values. + (parse_content_range): Handle '*' instance-length field. + 2008-01-25 Micah Cowan * main.c: Added notes to translators regarding (C), diacritics diff --git a/src/http.c b/src/http.c index 1729b5cb..da4b32e3 100644 --- a/src/http.c +++ b/src/http.c @@ -864,8 +864,11 @@ parse_content_range (const char *hdr, wgint *first_byte_ptr, return false; *last_byte_ptr = num; ++hdr; - for (num = 0; c_isdigit (*hdr); hdr++) - num = 10 * num + (*hdr - '0'); + if (*hdr == '*') + num = -1; + else + for (num = 0; c_isdigit (*hdr); hdr++) + num = 10 * num + (*hdr - '0'); *entity_length_ptr = num; return true; } @@ -2052,7 +2055,10 @@ File `%s' already there; not retrieving.\n\n"), hs->local_file); wgint first_byte_pos, last_byte_pos, entity_length; if (parse_content_range (hdrval, &first_byte_pos, &last_byte_pos, &entity_length)) - contrange = first_byte_pos; + { + contrange = first_byte_pos; + contlen = last_byte_pos - first_byte_pos + 1; + } } resp_free (resp); @@ -2152,7 +2158,10 @@ File `%s' already there; not retrieving.\n\n"), hs->local_file); CLOSE_INVALIDATE (sock); return RANGEERR; } - hs->contlen = contlen + contrange; + if (contlen == -1) + hs->contlen = -1; + else + hs->contlen = contlen + contrange; if (opt.verbose) { -- 2.39.2