From 3ce4ce9653fa2d5e68a7800a8943a9d2ace15bba Mon Sep 17 00:00:00 2001 From: James Bursa Date: Thu, 28 Aug 2003 20:04:35 +0000 Subject: [project @ 2003-08-28 20:04:35 by bursa] Use Content-Length to give percentage downloads. svn path=/import/netsurf/; revision=256 --- content/fetch.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'content/fetch.c') diff --git a/content/fetch.c b/content/fetch.c index 68fdb6b89..eb79afae3 100644 --- a/content/fetch.c +++ b/content/fetch.c @@ -47,6 +47,7 @@ struct fetch char *host; int status_code; char *location; + unsigned long content_length; struct fetch *queue; struct fetch *prev; struct fetch *next; @@ -145,6 +146,7 @@ struct fetch * fetch_start(char *url, char *referer, if (uri->server != 0) fetch->host = xstrdup(uri->server); fetch->status_code = 0; + fetch->content_length = 0; fetch->queue = 0; fetch->prev = 0; fetch->next = 0; @@ -420,6 +422,12 @@ size_t fetch_curl_header(char * data, size_t size, size_t nmemb, struct fetch *f f->location[i] == '\r' || f->location[i] == '\n'; i--) f->location[i] = '\0'; + } else if (15 < size && strncasecmp(data, "Content-Length:", 15) == 0) { + /* extract Content-Length header */ + for (i = 15; data[i] == ' ' || data[i] == '\t'; i++) + ; + if ('0' <= data[i] && data[i] <= '9') + f->content_length = atol(data + i); } return size; } @@ -463,7 +471,7 @@ int fetch_process_headers(struct fetch *f) } LOG(("FETCH_TYPE, '%s'", type)); - f->callback(FETCH_TYPE, f->p, type, 0); + f->callback(FETCH_TYPE, f->p, type, f->content_length); if (f->aborting) { f->in_callback = 0; return 1; -- cgit v1.2.3