summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--content/content.h2
-rw-r--r--content/fetch.c10
-rw-r--r--content/fetchcache.c8
3 files changed, 17 insertions, 3 deletions
diff --git a/content/content.h b/content/content.h
index bc189c1dd..0f2087b8e 100644
--- a/content/content.h
+++ b/content/content.h
@@ -182,7 +182,7 @@ struct content
struct content_user *user_list;
char status_message[80];
struct fetch *fetch;
- unsigned long fetch_size;
+ unsigned long fetch_size, total_size;
};
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;
diff --git a/content/fetchcache.c b/content/fetchcache.c
index 99686efe0..1c950ba4b 100644
--- a/content/fetchcache.c
+++ b/content/fetchcache.c
@@ -66,6 +66,7 @@ void fetchcache_callback(fetch_msg msg, void *p, char *data, unsigned long size)
switch (msg) {
case FETCH_TYPE:
+ c->total_size = size;
mime_type = xstrdup(data);
if ((semic = strchr(mime_type, ';')) != 0)
*semic = 0; /* remove "; charset=..." */
@@ -78,7 +79,12 @@ void fetchcache_callback(fetch_msg msg, void *p, char *data, unsigned long size)
case FETCH_DATA:
LOG(("FETCH_DATA"));
c->fetch_size += size;
- sprintf(c->status_message, "Received %lu bytes", c->fetch_size);
+ if (c->total_size)
+ sprintf(c->status_message, "Received %lu of %lu bytes (%u%%)",
+ c->fetch_size, c->total_size,
+ (unsigned int) (c->fetch_size * 100.0 / c->total_size));
+ else
+ sprintf(c->status_message, "Received %lu bytes", c->fetch_size);
content_broadcast(c, CONTENT_MSG_STATUS, 0);
content_process_data(c, data, size);
break;