Example #1
0
static time_t
httpReplyHdrExpirationTime_(const HttpReply * rep)
{
	if (rep->cache_control)
	{
		if (rep->date >= 0)
		{
			if (rep->cache_control->s_maxage >= 0)
				return rep->date + rep->cache_control->s_maxage;
			if (rep->cache_control->max_age >= 0)
				return rep->date + rep->cache_control->max_age;
		}
		else
		{
			if (rep->cache_control->s_maxage >= 0)
				return squid_curtime;
			if (rep->cache_control->max_age >= 0)
				return squid_curtime;
		}
	}
	if (Config.onoff.vary_ignore_expire &&
			httpHeaderHas(&rep->header, HDR_VARY))
	{
		const time_t d = httpHeaderGetTime(&rep->header, HDR_DATE);
		const time_t e = httpHeaderGetTime(&rep->header, HDR_EXPIRES);
		if (d == e)
			return -1;
	}
	if (httpHeaderHas(&rep->header, HDR_EXPIRES))
	{
		const time_t e = httpHeaderGetTime(&rep->header, HDR_EXPIRES);
		return e < 0 ? squid_curtime : e;
	}
	return -1;
}
Example #2
0
/* sync this routine when you update HttpReply struct */
static void
httpReplyHdrCacheInit(HttpReply * rep)
{
    const HttpHeader *hdr = &rep->header;
    const char *str;
    rep->content_length = httpHeaderGetSize(hdr, HDR_CONTENT_LENGTH);
    rep->date = httpHeaderGetTime(hdr, HDR_DATE);
    rep->last_modified = httpHeaderGetTime(hdr, HDR_LAST_MODIFIED);
    str = httpHeaderGetStr(hdr, HDR_CONTENT_TYPE);
    if (str)
	stringLimitInit(&rep->content_type, str, strcspn(str, ";\t "));
    else
	rep->content_type = StringNull;
    rep->cache_control = httpHeaderGetCc(hdr);
    rep->content_range = httpHeaderGetContRange(hdr);
    rep->keep_alive = httpMsgIsPersistent(rep->sline.version, &rep->header);
    /* be sure to set expires after date and cache-control */
    rep->expires = httpReplyHdrExpirationTime(rep);
}
Example #3
0
static time_t
httpReplyHdrExpirationTime(const HttpReply * rep)
{
    /* The s-maxage and max-age directive takes priority over Expires */
    if (rep->cache_control) {
	if (rep->date >= 0) {
	    if (rep->cache_control->s_maxage >= 0)
		return rep->date + rep->cache_control->s_maxage;
	    if (rep->cache_control->max_age >= 0)
		return rep->date + rep->cache_control->max_age;
	} else {
	    /*
	     * Conservatively handle the case when we have a max-age
	     * header, but no Date for reference?
	     */
	    if (rep->cache_control->s_maxage >= 0)
		return squid_curtime;
	    if (rep->cache_control->max_age >= 0)
		return squid_curtime;
	}
    }
    if (Config.onoff.vary_ignore_expire &&
	httpHeaderHas(&rep->header, HDR_VARY)) {
	const time_t d = httpHeaderGetTime(&rep->header, HDR_DATE);
	const time_t e = httpHeaderGetTime(&rep->header, HDR_EXPIRES);
	if (d == e)
	    return -1;
    }
    if (httpHeaderHas(&rep->header, HDR_EXPIRES)) {
	const time_t e = httpHeaderGetTime(&rep->header, HDR_EXPIRES);
	/*
	 * HTTP/1.0 says that robust implementations should consider
	 * bad or malformed Expires header as equivalent to "expires
	 * immediately."
	 */
	return e < 0 ? squid_curtime : e;
    }
    return -1;
}