diff --git a/plugin/business/pangu-http/pangu_http.cpp b/plugin/business/pangu-http/pangu_http.cpp index 9fcf796..cdf87a9 100644 --- a/plugin/business/pangu-http/pangu_http.cpp +++ b/plugin/business/pangu-http/pangu_http.cpp @@ -889,9 +889,10 @@ void cache_make_response(const struct tfe_http_session * session, struct pangu_h 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); - assert(cont_len==evbuffer_get_length(ctx->cached_body)); + char temp[TFE_STRING_MAX]; + snprintf(temp, sizeof(temp), "%lu", ctx->cached_header->content_length); + tfe_http_std_field_write(cached_response, TFE_HTTP_CONT_LENGTH, temp); + assert(ctx->cached_header->content_length==evbuffer_get_length(ctx->cached_body)); tfe_http_half_append_body(cached_response, (char*)evbuffer_pullup(ctx->cached_body, -1), evbuffer_get_length(ctx->cached_body), 0); tfe_http_half_append_body(cached_response, NULL, 0, 0); diff --git a/plugin/business/pangu-http/pangu_web_cache.cpp b/plugin/business/pangu-http/pangu_web_cache.cpp index 8164e87..8dd7c03 100644 --- a/plugin/business/pangu-http/pangu_web_cache.cpp +++ b/plugin/business/pangu-http/pangu_web_cache.cpp @@ -61,7 +61,6 @@ static char* read_http1_hdr(const char* hdr, const char* field_name) } void cache_query_free_meta(struct cached_meta* meta) { - FREE(&meta->content_length); FREE(&meta->content_type); FREE(&meta); return; @@ -89,7 +88,7 @@ struct cached_meta* cache_query_result_get_header(future_result_t * result) return NULL; } meta= ALLOC(struct cached_meta, 1); - meta->content_length=read_http1_hdr((const char*)cache_result->data_frag, "content-length"); + meta->content_length=cache_result->tlength; meta->content_type=read_http1_hdr((const char*)cache_result->data_frag, "content-type"); return meta; } diff --git a/plugin/business/pangu-http/pangu_web_cache.h b/plugin/business/pangu-http/pangu_web_cache.h index 350f52b..f87c73b 100644 --- a/plugin/business/pangu-http/pangu_web_cache.h +++ b/plugin/business/pangu-http/pangu_web_cache.h @@ -15,7 +15,7 @@ struct cache_handle; struct cache_handle* create_web_cache_handle(const char* profile_path, const char* section, void *logger); struct cached_meta { - char* content_length; + size_t content_length; char* content_type; }; struct cached_meta* cache_query_result_get_header(future_result_t * result);