|
|
|
|
@@ -454,6 +454,7 @@ static void cache_query_on_succ(future_result_t * result, void * user)
|
|
|
|
|
ctx->f_cache_query=NULL;
|
|
|
|
|
tfe_http_session_resume(ctx->ref_session);
|
|
|
|
|
ctx->resume_from_cache_query=1;
|
|
|
|
|
printf("cache query success: %s\n", ctx->ref_session->req->req_spec.url);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(cache_query_result_is_header(result))
|
|
|
|
|
@@ -474,7 +475,8 @@ static void cache_query_on_fail(enum e_future_error err, const char * what, void
|
|
|
|
|
ctx->f_cache_query=NULL;
|
|
|
|
|
tfe_http_session_resume(ctx->ref_session);
|
|
|
|
|
ctx->cache_query_status=WEB_CACHE_NOT_HIT;
|
|
|
|
|
ctx->resume_from_cache_query=1;
|
|
|
|
|
ctx->resume_from_cache_query=1;
|
|
|
|
|
printf("cache query failed: %s\n", ctx->ref_session->req->req_spec.url);
|
|
|
|
|
}
|
|
|
|
|
void http_replace(const struct tfe_stream * stream, const struct tfe_http_session * session,
|
|
|
|
|
enum tfe_http_event events, const unsigned char * body_frag, size_t frag_size, struct pangu_http_ctx * ctx)
|
|
|
|
|
@@ -852,6 +854,10 @@ void cache_update(const struct tfe_http_session * session, enum tfe_http_event e
|
|
|
|
|
if(events & EV_HTTP_RESP_BODY_BEGIN && ctx->cache_query_status == WEB_CACHE_NOT_HIT)
|
|
|
|
|
{
|
|
|
|
|
ctx->cache_update_ctx=web_cache_update_start(g_pangu_rt->cache, thread_id, session);
|
|
|
|
|
if(ctx->cache_update_ctx==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("cache update forbidden: %s\n", ctx->ref_session->req->req_spec.url);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(events & EV_HTTP_RESP_BODY_CONT && ctx->cache_update_ctx!=NULL)
|
|
|
|
|
{
|
|
|
|
|
@@ -860,7 +866,8 @@ void cache_update(const struct tfe_http_session * session, enum tfe_http_event e
|
|
|
|
|
if(events & EV_HTTP_RESP_BODY_END && ctx->cache_update_ctx!=NULL)
|
|
|
|
|
{
|
|
|
|
|
web_cache_update_end(ctx->cache_update_ctx);
|
|
|
|
|
ctx->cache_update_ctx=NULL;
|
|
|
|
|
ctx->cache_update_ctx=NULL;
|
|
|
|
|
printf("cache update success: %s\n", ctx->ref_session->req->req_spec.url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@@ -869,6 +876,7 @@ void cache_make_response(const struct tfe_http_session * session, struct pangu_h
|
|
|
|
|
size_t cont_len=0;
|
|
|
|
|
struct tfe_http_session * wr_session=tfe_http_session_allow_write(session);
|
|
|
|
|
struct tfe_http_half* cached_response=tfe_http_session_response_create(wr_session, 200);
|
|
|
|
|
tfe_http_nonstd_field_write(cached_response, "X-Cache-Lookup", "Hit From MESA-TFE");
|
|
|
|
|
tfe_http_std_field_write(cached_response, TFE_HTTP_CONT_TYPE, ctx->cached_header->content_type);
|
|
|
|
|
tfe_http_std_field_write(cached_response, TFE_HTTP_CONT_LENGTH, ctx->cached_header->content_length);
|
|
|
|
|
sscanf(ctx->cached_header->content_length, "%llu", &cont_len);
|
|
|
|
|
@@ -956,8 +964,10 @@ void pangu_on_http_data(const struct tfe_stream * stream, const struct tfe_http_
|
|
|
|
|
cache_make_response(session, ctx);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enforce_control_policy(stream, session, events, body_frag, frag_size,thread_id, ctx);
|
|
|
|
|
if(!ctx->resume_from_cache_query)
|
|
|
|
|
{
|
|
|
|
|
enforce_control_policy(stream, session, events, body_frag, frag_size,thread_id, ctx);
|
|
|
|
|
}
|
|
|
|
|
if(ctx->action != PG_ACTION_NONE)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
|