mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Reflow check_head_for_cache_control
This commit is contained in:
parent
2a2aad15f9
commit
a8f28f21c9
@ -365,67 +365,68 @@ static void
|
||||
check_head_for_cache_control(struct html_context *html_context,
|
||||
unsigned char *head)
|
||||
{
|
||||
if (!get_opt_bool("document.cache.ignore_cache_control", NULL)) {
|
||||
unsigned char *d;
|
||||
int no_cache = 0;
|
||||
time_t expires = 0;
|
||||
unsigned char *d;
|
||||
int no_cache = 0;
|
||||
time_t expires = 0;
|
||||
|
||||
/* XXX: Code duplication with HTTP protocol backend. */
|
||||
/* I am not entirely sure in what order we should process these
|
||||
* headers and if we should still process Cache-Control max-age
|
||||
* if we already set max age to date mentioned in Expires.
|
||||
* --jonas */
|
||||
if ((d = parse_header(head, "Pragma", NULL))) {
|
||||
if (strstr(d, "no-cache")) {
|
||||
no_cache = 1;
|
||||
}
|
||||
mem_free(d);
|
||||
if (get_opt_bool("document.cache.ignore_cache_control", NULL))
|
||||
return;
|
||||
|
||||
/* XXX: Code duplication with HTTP protocol backend. */
|
||||
/* I am not entirely sure in what order we should process these
|
||||
* headers and if we should still process Cache-Control max-age
|
||||
* if we already set max age to date mentioned in Expires.
|
||||
* --jonas */
|
||||
if ((d = parse_header(head, "Pragma", NULL))) {
|
||||
if (strstr(d, "no-cache")) {
|
||||
no_cache = 1;
|
||||
}
|
||||
|
||||
if (!no_cache && (d = parse_header(head, "Cache-Control", NULL))) {
|
||||
if (strstr(d, "no-cache") || strstr(d, "must-revalidate")) {
|
||||
no_cache = 1;
|
||||
|
||||
} else {
|
||||
unsigned char *pos = strstr(d, "max-age=");
|
||||
|
||||
assert(!no_cache);
|
||||
|
||||
if (pos) {
|
||||
/* Grab the number of seconds. */
|
||||
timeval_T max_age, seconds;
|
||||
|
||||
timeval_from_seconds(&seconds, atol(pos + 8));
|
||||
timeval_now(&max_age);
|
||||
timeval_add_interval(&max_age, &seconds);
|
||||
|
||||
expires = timeval_to_seconds(&max_age);
|
||||
}
|
||||
}
|
||||
|
||||
mem_free(d);
|
||||
}
|
||||
|
||||
if (!no_cache && (d = parse_header(head, "Expires", NULL))) {
|
||||
/* Convert date to seconds. */
|
||||
if (strstr(d, "now")) {
|
||||
timeval_T now;
|
||||
|
||||
timeval_now(&now);
|
||||
expires = timeval_to_seconds(&now);
|
||||
} else {
|
||||
expires = parse_date(&d, NULL, 0, 1);
|
||||
}
|
||||
|
||||
mem_free(d);
|
||||
}
|
||||
|
||||
if (no_cache)
|
||||
html_context->special_f(html_context, SP_CACHE_CONTROL);
|
||||
else if (expires)
|
||||
html_context->special_f(html_context,
|
||||
SP_CACHE_EXPIRES, expires);
|
||||
mem_free(d);
|
||||
}
|
||||
|
||||
if (!no_cache && (d = parse_header(head, "Cache-Control", NULL))) {
|
||||
if (strstr(d, "no-cache") || strstr(d, "must-revalidate")) {
|
||||
no_cache = 1;
|
||||
|
||||
} else {
|
||||
unsigned char *pos = strstr(d, "max-age=");
|
||||
|
||||
assert(!no_cache);
|
||||
|
||||
if (pos) {
|
||||
/* Grab the number of seconds. */
|
||||
timeval_T max_age, seconds;
|
||||
|
||||
timeval_from_seconds(&seconds, atol(pos + 8));
|
||||
timeval_now(&max_age);
|
||||
timeval_add_interval(&max_age, &seconds);
|
||||
|
||||
expires = timeval_to_seconds(&max_age);
|
||||
}
|
||||
}
|
||||
|
||||
mem_free(d);
|
||||
}
|
||||
|
||||
if (!no_cache && (d = parse_header(head, "Expires", NULL))) {
|
||||
/* Convert date to seconds. */
|
||||
if (strstr(d, "now")) {
|
||||
timeval_T now;
|
||||
|
||||
timeval_now(&now);
|
||||
expires = timeval_to_seconds(&now);
|
||||
} else {
|
||||
expires = parse_date(&d, NULL, 0, 1);
|
||||
}
|
||||
|
||||
mem_free(d);
|
||||
}
|
||||
|
||||
if (no_cache)
|
||||
html_context->special_f(html_context, SP_CACHE_CONTROL);
|
||||
else if (expires)
|
||||
html_context->special_f(html_context,
|
||||
SP_CACHE_EXPIRES, expires);
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user