正确处理etag和last_modified元信息。
This commit is contained in:
@@ -935,8 +935,10 @@ static void cache_query_on_succ(future_result_t * result, void * user)
|
|||||||
tfe_http_session_resume(ctx->ref_session);
|
tfe_http_session_resume(ctx->ref_session);
|
||||||
|
|
||||||
ctx->cached_response=tfe_http_session_response_create(ctx->ref_session, 200);
|
ctx->cached_response=tfe_http_session_response_create(ctx->ref_session, 200);
|
||||||
tfe_http_nonstd_field_write(ctx->cached_response, "X-Cache-Lookup", "Hit From TFE");
|
|
||||||
tfe_http_std_field_write(ctx->cached_response, TFE_HTTP_CONT_TYPE, meta->content_type);
|
tfe_http_std_field_write(ctx->cached_response, TFE_HTTP_CONT_TYPE, meta->content_type);
|
||||||
|
tfe_http_std_field_write(ctx->cached_response, TFE_HTTP_LAST_MODIFIED, meta->last_modified);
|
||||||
|
tfe_http_std_field_write(ctx->cached_response, TFE_HTTP_ETAG, meta->etag);
|
||||||
|
tfe_http_nonstd_field_write(ctx->cached_response, "X-Cache-Lookup", "Hit From TFE");
|
||||||
snprintf(temp, sizeof(temp), "%lu", meta->content_length);
|
snprintf(temp, sizeof(temp), "%lu", meta->content_length);
|
||||||
tfe_http_std_field_write(ctx->cached_response, TFE_HTTP_CONT_LENGTH, temp);
|
tfe_http_std_field_write(ctx->cached_response, TFE_HTTP_CONT_LENGTH, temp);
|
||||||
|
|
||||||
|
|||||||
@@ -271,40 +271,6 @@ static char* read_http1_hdr(const char* hdr, const char* field_name)
|
|||||||
memcpy(value, p, q-p);
|
memcpy(value, p, q-p);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum cache_query_result_type cache_query_result_get_type(future_result_t * result)
|
|
||||||
{
|
|
||||||
struct tango_cache_result* cache_result=tango_cache_read_result(result);
|
|
||||||
enum cache_query_result_type map[__CACHE_QUERY_RESULT_MAX];
|
|
||||||
map[RESULT_TYPE_BODY]=CACHE_QUERY_RESULT_DATA;
|
|
||||||
map[RESULT_TYPE_HEADER]=CACHE_QUERY_RESULT_META;
|
|
||||||
map[RESULT_TYPE_USERTAG]=CACHE_QUERY_RESULT_IRRELEVANT;
|
|
||||||
map[RESULT_TYPE_END]=CACHE_QUERY_RESULT_END;
|
|
||||||
map[RESULT_TYPE_MISS]=CACHE_QUERY_RESULT_MISS;
|
|
||||||
return map[cache_result->type];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct cached_meta* cache_query_result_get_header(future_result_t * result)
|
|
||||||
{
|
|
||||||
struct tango_cache_result* cache_result=tango_cache_read_result(result);
|
|
||||||
struct cached_meta* meta;
|
|
||||||
if(cache_result->type!=RESULT_TYPE_HEADER)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
meta= ALLOC(struct cached_meta, 1);
|
|
||||||
meta->content_length=cache_result->tlength;
|
|
||||||
meta->content_type=read_http1_hdr((const char*)cache_result->data_frag, "content-type");
|
|
||||||
return meta;
|
|
||||||
}
|
|
||||||
size_t cache_query_result_get_data(future_result_t * result, const unsigned char** pp_data)
|
|
||||||
{
|
|
||||||
struct tango_cache_result* cache_result=tango_cache_read_result(result);
|
|
||||||
assert(cache_result->type==RESULT_TYPE_BODY);
|
|
||||||
*pp_data=(const unsigned char*)cache_result->data_frag;
|
|
||||||
return cache_result->size;
|
|
||||||
}
|
|
||||||
struct cache_query_context
|
struct cache_query_context
|
||||||
{
|
{
|
||||||
struct cache_handle* ref_handle;
|
struct cache_handle* ref_handle;
|
||||||
@@ -315,6 +281,29 @@ struct cache_query_context
|
|||||||
struct tango_cache_result* ref_tango_cache_result;
|
struct tango_cache_result* ref_tango_cache_result;
|
||||||
struct future* f_tango_cache_fetch;
|
struct future* f_tango_cache_fetch;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum cache_query_result_type cache_query_result_get_type(future_result_t * result)
|
||||||
|
{
|
||||||
|
struct cache_query_context* ctx=(struct cache_query_context*)result;
|
||||||
|
struct tango_cache_result* cache_result=ctx->ref_tango_cache_result;
|
||||||
|
enum cache_query_result_type map[__CACHE_QUERY_RESULT_MAX];
|
||||||
|
map[RESULT_TYPE_BODY]=CACHE_QUERY_RESULT_DATA;
|
||||||
|
map[RESULT_TYPE_HEADER]=CACHE_QUERY_RESULT_META;
|
||||||
|
map[RESULT_TYPE_USERTAG]=CACHE_QUERY_RESULT_IRRELEVANT;
|
||||||
|
map[RESULT_TYPE_END]=CACHE_QUERY_RESULT_END;
|
||||||
|
map[RESULT_TYPE_MISS]=CACHE_QUERY_RESULT_MISS;
|
||||||
|
return map[cache_result->type];
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t cache_query_result_get_data(future_result_t * result, const unsigned char** pp_data)
|
||||||
|
{
|
||||||
|
struct cache_query_context* ctx=(struct cache_query_context*)result;
|
||||||
|
struct tango_cache_result* cache_result=ctx->ref_tango_cache_result;
|
||||||
|
assert(cache_result->type==RESULT_TYPE_BODY);
|
||||||
|
*pp_data=(const unsigned char*)cache_result->data_frag;
|
||||||
|
return cache_result->size;
|
||||||
|
}
|
||||||
|
|
||||||
void cache_query_ctx_free_cb(void* p)
|
void cache_query_ctx_free_cb(void* p)
|
||||||
{
|
{
|
||||||
struct cache_query_context* ctx=(struct cache_query_context*)p;
|
struct cache_query_context* ctx=(struct cache_query_context*)p;
|
||||||
@@ -340,6 +329,10 @@ void cached_meta_set(struct cached_meta* meta, enum CACHE_RESULT_TYPE type, cons
|
|||||||
break;
|
break;
|
||||||
case RESULT_TYPE_USERTAG:
|
case RESULT_TYPE_USERTAG:
|
||||||
meta->last_modified=read_http1_hdr(data_frag, "Last-Modified");
|
meta->last_modified=read_http1_hdr(data_frag, "Last-Modified");
|
||||||
|
if(0==strcasecmp(meta->last_modified, "Thu, 01 Jan 1970 00:00:00 GMT"))
|
||||||
|
{
|
||||||
|
FREE(&(meta->last_modified));
|
||||||
|
}
|
||||||
meta->etag=read_http1_hdr(data_frag, "etag");
|
meta->etag=read_http1_hdr(data_frag, "etag");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -353,19 +346,18 @@ static void cache_query_obj_on_succ(future_result_t * result, void * user)
|
|||||||
{
|
{
|
||||||
struct promise * p = (struct promise *) user;
|
struct promise * p = (struct promise *) user;
|
||||||
struct cache_query_context* ctx=(struct cache_query_context*)promise_get_ctx(p);
|
struct cache_query_context* ctx=(struct cache_query_context*)promise_get_ctx(p);
|
||||||
struct tango_cache_result* _result=tango_cache_read_result(result);
|
ctx->ref_tango_cache_result=tango_cache_read_result(result);
|
||||||
|
switch(ctx->ref_tango_cache_result->type)
|
||||||
switch(_result->type)
|
|
||||||
{
|
{
|
||||||
case RESULT_TYPE_HEADER:
|
case RESULT_TYPE_HEADER:
|
||||||
ATOMIC_INC(&(ctx->ref_handle->stat_val[STAT_CACHE_QUERY_HIT]));
|
ATOMIC_INC(&(ctx->ref_handle->stat_val[STAT_CACHE_QUERY_HIT]));
|
||||||
FS_operate(ctx->ref_handle->fs_handle, ctx->ref_handle->fs_id[STAT_CACHE_QUERY_HIT_OJB_SIZE], 0, FS_OP_SET, _result->tlength/1024);
|
FS_operate(ctx->ref_handle->fs_handle, ctx->ref_handle->fs_id[STAT_CACHE_QUERY_HIT_OJB_SIZE], 0, FS_OP_SET, ctx->ref_tango_cache_result->tlength/1024);
|
||||||
cached_meta_set(&ctx->meta, RESULT_TYPE_HEADER, _result->data_frag, _result->size);
|
cached_meta_set(&ctx->meta, RESULT_TYPE_HEADER, ctx->ref_tango_cache_result->data_frag, ctx->ref_tango_cache_result->size);
|
||||||
ctx->meta.content_length=_result->tlength;
|
ctx->meta.content_length=ctx->ref_tango_cache_result->tlength;
|
||||||
TFE_LOG_DEBUG(ctx->ref_handle->logger, "cache query hit: %s", ctx->url);
|
TFE_LOG_DEBUG(ctx->ref_handle->logger, "cache query hit: %s", ctx->url);
|
||||||
break;
|
break;
|
||||||
case RESULT_TYPE_USERTAG:
|
case RESULT_TYPE_USERTAG:
|
||||||
cached_meta_set(&ctx->meta, RESULT_TYPE_USERTAG, _result->data_frag, _result->size);
|
cached_meta_set(&ctx->meta, RESULT_TYPE_USERTAG, ctx->ref_tango_cache_result->data_frag, ctx->ref_tango_cache_result->size);
|
||||||
break;
|
break;
|
||||||
case RESULT_TYPE_MISS:
|
case RESULT_TYPE_MISS:
|
||||||
TFE_LOG_DEBUG(ctx->ref_handle->logger, "cache query miss: %s", ctx->url);
|
TFE_LOG_DEBUG(ctx->ref_handle->logger, "cache query miss: %s", ctx->url);
|
||||||
@@ -377,12 +369,12 @@ static void cache_query_obj_on_succ(future_result_t * result, void * user)
|
|||||||
cache_query_ctx_free_cb(ctx);
|
cache_query_ctx_free_cb(ctx);
|
||||||
break;
|
break;
|
||||||
case RESULT_TYPE_BODY:
|
case RESULT_TYPE_BODY:
|
||||||
ATOMIC_ADD(&(ctx->ref_handle->stat_val[STAT_CACHE_QUERY_BYTES]), _result->size);
|
ATOMIC_ADD(&(ctx->ref_handle->stat_val[STAT_CACHE_QUERY_BYTES]), ctx->ref_tango_cache_result->size);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
promise_success(p, result);
|
promise_success(p, ctx);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user