From 7476f84fa1e4b806d5b3be71ed88cf91f39eb0bc Mon Sep 17 00:00:00 2001 From: fengweihao Date: Thu, 5 Dec 2019 19:04:04 +0800 Subject: [PATCH] =?UTF-8?q?TSG-376=20=E4=BF=AE=E5=A4=8DProxy=20Event=20Log?= =?UTF-8?q?s=E4=B8=ADRequest=20Line=E3=80=81Response=20Line=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E4=B8=BA=E7=A9=BA=EF=BC=8CStream=20Trace=20Id?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=B8=BA0=201)=E4=BF=AE=E5=A4=8D=E9=87=8D?= =?UTF-8?q?=E5=AE=9A=E5=90=91=E5=91=BD=E4=B8=ADURL+=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=A4=B4=EF=BC=8C=E5=9F=9F=E5=90=8D=E8=BE=93=E5=85=A5=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E9=A1=B5=E9=9D=A2=E6=9C=AC=E8=BA=AB=E9=87=8D=E5=AE=9A?= =?UTF-8?q?=E5=90=91=E5=A4=B1=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/pangu-http/src/pangu_logger.cpp | 25 ++++++++++++++++--- plugin/protocol/http2/src/http2_common.cpp | 3 ++- plugin/protocol/http2/src/http2_stream.cpp | 15 ++++++----- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/plugin/business/pangu-http/src/pangu_logger.cpp b/plugin/business/pangu-http/src/pangu_logger.cpp index 9c0cce9..1759d95 100644 --- a/plugin/business/pangu-http/src/pangu_logger.cpp +++ b/plugin/business/pangu-http/src/pangu_logger.cpp @@ -214,18 +214,35 @@ int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg) cJSON_AddStringToObject(common_obj, "http_version", app_proto[http->major_version]); cJSON_AddStringToObject(common_obj, "common_schema_type", "HTTP"); - uint64_t opt_val; - uint16_t opt_out_size; + char opt_val[24]; uint16_t opt_out_size; struct tfe_cmsg * cmsg = tfe_stream_get0_cmsg(log_msg->stream); if (cmsg!=NULL) { - int ret=tfe_cmsg_get_value(cmsg, TFE_CMSG_STREAM_TRACE_ID, (unsigned char *) &opt_val, sizeof(opt_val), &opt_out_size); + int ret=tfe_cmsg_get_value(cmsg, TFE_CMSG_STREAM_TRACE_ID, (unsigned char *) opt_val, sizeof(opt_val), &opt_out_size); if (ret==0) { - cJSON_AddNumberToObject(common_obj, "common_stream_trace_id", opt_val); + cJSON_AddStringToObject(common_obj, "common_stream_trace_id", opt_val); } } + if (http->req) + { + char *request_line=NULL; + struct tfe_http_req_spec req_spec=http->req->req_spec; + asprintf(&request_line, "%s %s HTTP/%d.%d", http_std_method_to_string(req_spec.method), req_spec.url, http->major_version, http->minor_version); + cJSON_AddStringToObject(common_obj, "http_request_line", request_line); + free(request_line); + } + + if (http->resp) + { + char *response_line=NULL; + struct tfe_http_resp_spec resp_spec=http->resp->resp_spec; + asprintf(&response_line, "HTTP/%d.%d %d OK", http->major_version, http->minor_version, resp_spec.resp_code); + cJSON_AddStringToObject(common_obj, "http_response_line", response_line); + free(response_line); + } + switch(addr->addrtype) { case TFE_ADDR_STREAM_TUPLE4_V4: diff --git a/plugin/protocol/http2/src/http2_common.cpp b/plugin/protocol/http2/src/http2_common.cpp index 0eb2521..8135c4c 100644 --- a/plugin/protocol/http2/src/http2_common.cpp +++ b/plugin/protocol/http2/src/http2_common.cpp @@ -224,8 +224,9 @@ static int inflate_gzip_read(struct z_stream_st **strm, char **dest, int *outlen (*strm)->zst.avail_out = CHUNK; (*strm)->zst.next_out = out; ret = inflate(&((*strm)->zst), Z_NO_FLUSH); - assert(ret != Z_STREAM_ERROR); /* state not clobbered */ switch (ret) { + case Z_STREAM_ERROR: + ret = Z_STREAM_ERROR; case Z_NEED_DICT: ret = Z_DATA_ERROR; /* and fall through */ case Z_DATA_ERROR: diff --git a/plugin/protocol/http2/src/http2_stream.cpp b/plugin/protocol/http2/src/http2_stream.cpp index 8f5446a..9a2ca24 100644 --- a/plugin/protocol/http2/src/http2_stream.cpp +++ b/plugin/protocol/http2/src/http2_stream.cpp @@ -731,6 +731,13 @@ nghttp2_frame_submit_built_resp(struct tfe_h2_stream *h2_stream_info, if (h2_header->nvlen <= 0) return ACTION_FORWARD_DATA; + char value[128] = {0}; struct http_field_name field; + field.field_id = TFE_HTTP_UNKNOWN_FIELD; + field.field_name = ":status"; + snprintf(value, sizeof(value), "%d", pangu_resp->method_or_status); + tfe_http_nonstd_field_write(&pangu_resp->half_public, ":status", NULL); + tfe_h2_header_add_field(h2_header, &field, (const char *)value, 0); + struct tfe_h2_payload *body = &pangu_resp->h2_payload; body->flags |= NGHTTP2_FLAG_END_STREAM; char str_sz_evbuf_body[TFE_STRING_MAX]; @@ -1507,11 +1514,6 @@ nghttp2_submit_built_response(struct tfe_h2_stream *h2_stream_info, snprintf(value, sizeof(value), "tfe/%s", tfe_version()); tfe_h2_header_add_field(&resp->header, &field, (const char *)value, 0); - field.field_id = TFE_HTTP_UNKNOWN_FIELD; - field.field_name = ":status"; - snprintf(value, sizeof(value), "%d", resp->method_or_status); - tfe_h2_header_add_field(&resp->header, &field, (const char *)value, 0); - stream_action = nghttp2_frame_submit_built_resp(h2_stream_info, h2_session); if (stream_action == ACTION_DROP_DATA) { @@ -1544,7 +1546,8 @@ nghttp2_server_frame_submit_header(struct tfe_h2_stream *h2_stream_info, { stream_action = nghttp2_submit_built_response(h2_stream_info, h2_session); } - else{ + else + { stream_action = (enum tfe_stream_action)ACTION_USER_DATA; } return stream_action;