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 19, 2016
1 parent 798299d commit 66323a7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
18 changes: 18 additions & 0 deletions tempesta_fw/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <linux/tcp.h>
#include <linux/topology.h>


#include "tdb.h"

#include "tempesta_fw.h"
Expand Down Expand Up @@ -216,6 +217,8 @@ tfw_cache_msg_cacheable(TfwHttpReq *req)
return __cache_method_test(req->method);
}



/*
* Find caching policy in specific vhost and location.
*/
Expand Down Expand Up @@ -368,7 +371,22 @@ 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__ */
33 changes: 32 additions & 1 deletion tempesta_fw/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,35 @@ tfw_http_add_hdr_via(TfwHttpMsg *hm)
TFW_DBG2("Added Via: header to msg [%p]\n", hm);
return r;
}
static int
tfw_http_add_hdr_110(TfwHttpMsg *hm)
{
int r;
static const char const * __read_mostly s_110 = "Response is Stale";
TfwVhost *vhost = tfw_vhost_get_default();

TfwStr rh = {
#define S_Stale "Warning: 110 -"
.ptr = (TfwStr []) {
{ .ptr = S_Stale, .len = SLEN(S_Stale) },
{ .ptr = (void *)s_110,
.len = SLEN(s_110) },
{ .ptr = *this_cpu_ptr(&g_buf),
.len = vhost->hdr_via_len },
},
.len = SLEN(S_Stale) + SLEN(s_110) + 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 Via: header to msg [%p]\n", hm);
else
TFW_DBG2("Added Via: header to msg [%p]\n", hm);
return r;
}
static int
tfw_http_add_x_forwarded_for(TfwHttpMsg *hm)
{
Expand Down Expand Up @@ -748,9 +776,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 +802,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 66323a7

Please sign in to comment.