Skip to content

Commit

Permalink
fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Lvov committed Jul 20, 2016
1 parent 798299d commit 2f703cb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
13 changes: 13 additions & 0 deletions tempesta_fw/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,20 @@ tfw_cache_entry_age(TfwCacheEntry *ce)
time_t initial_age = max(apparent_age, corrected_age);
return (initial_age + tfw_current_timestamp() - ce->resp_time);
}
/*RFC 7234 4.2.1
* If the cache is shared and the s-maxage response directive is pressent,
* use its value, or
* If the max-age response directive is present use its value, or
* if the Expires response header fild is present, use its value minus the
* value of the Date response header field. */
bool
tfw_cache_resp_is_stale(TfwHttpResp *resp)
{
bool r = false;

r = (tfw_cache_calc_lifetime(resp) < jiffies);
return r;
}
/*
* Given Cache Control arguments in the request and the response,
* as well as the stored cache entry parameters, determine if the
Expand Down
1 change: 1 addition & 0 deletions tempesta_fw/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@

int tfw_cache_process(TfwHttpReq *req, TfwHttpResp *resp,
tfw_http_cache_cb_t action);
bool tfw_cache_resp_is_stale(TfwHttpResp *resp);

#endif /* __TFW_CACHE_H__ */
35 changes: 34 additions & 1 deletion tempesta_fw/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,36 @@ tfw_http_add_hdr_via(TfwHttpMsg *hm)
return r;
}

static int
tfw_http_add_hdr_110(TfwHttpMsg *hm)
{
int r;
TfwVhost *vhost = tfw_vhost_get_default();
unsigned int vlen = SLEN("Response is stale. : ");

TfwStr rh = {
#define S_Stale "Warning: 110: "
.ptr = (TfwStr []) {
{ .ptr = S_Stale, .len = SLEN(S_Stale) },
{ .ptr = (void *)"Response is stale. : ",
.len = vlen },
{ .ptr = *this_cpu_ptr(&g_buf),
.len = vhost->hdr_via_len },
},
.len = SLEN(S_Stale) + vlen + vhost->hdr_via_len,
.eolen = 2,
.flags = 3 << TFW_STR_CN_SHIFT
#undef S_Stale
};

r = tfw_http_msg_hdr_add(hm, &rh);
if (r)
TFW_ERR("Unable to add 110: header to msg [%p]\n", hm);
else
TFW_DBG2("Added 110: header to msg [%p]\n", hm);
return r;
}

static int
tfw_http_add_x_forwarded_for(TfwHttpMsg *hm)
{
Expand Down Expand Up @@ -748,9 +778,11 @@ tfw_http_adjust_resp(TfwHttpResp *resp, TfwHttpReq *req)
return r;

r = tfw_http_add_hdr_via(hm);
if (tfw_cache_resp_is_stale(resp)) {
r = tfw_http_add_hdr_110(hm);
if (r)
return r;

}
if (!(resp->flags & TFW_HTTP_HAS_HDR_DATE)) {
r = tfw_http_set_hdr_date(hm);
if (r < 0)
Expand All @@ -772,6 +804,7 @@ tfw_http_req_cache_cb(TfwHttpReq *req, TfwHttpResp *resp)
int r;
TfwConnection *srv_conn;

TFW_DBG("http:req_cache_cb:\n");
if (resp) {
/*
* The request is served from cache.
Expand Down

0 comments on commit 2f703cb

Please sign in to comment.