From 92d96a5a492942ae4c50d91fc5af024879b04ab8 Mon Sep 17 00:00:00 2001 From: zhengchao Date: Mon, 15 Oct 2018 18:37:32 +0800 Subject: [PATCH] =?UTF-8?q?HTTP=E4=B8=9A=E5=8A=A1=E5=B1=82=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E8=8E=B7=E5=BE=97content-length=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=B8=8Etango=20cache=20client=20=E6=8E=A5=E5=8F=A3=E4=B8=8D?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/business/pangu-http/pangu_http.cpp | 7 ++++--- plugin/business/pangu-http/pangu_web_cache.cpp | 3 +-- plugin/business/pangu-http/pangu_web_cache.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) 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);