From 348afbc00d76c5ebc877c5067b30903fadd9ee3d Mon Sep 17 00:00:00 2001 From: fengweihao Date: Sat, 29 Jun 2019 19:39:29 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E5=A4=8D=E6=9B=BF=E6=8D=A2=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E7=BC=96=E7=A0=81=E5=A4=A7=E5=B0=8F=E5=86=99=E5=8C=B9?= =?UTF-8?q?=E9=85=8D=E9=94=99=E8=AF=AF=EF=BC=8C=E9=80=A0=E6=88=90=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=9B=BF=E6=8D=A2=E5=A4=B1=E8=B4=A5=202.=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=91=BD=E4=B8=ADinsert=E5=90=8E=EF=BC=8C=E5=8F=91?= =?UTF-8?q?=E9=80=81=E6=97=A0=E6=95=88=E6=97=A5=E5=BF=97=203.=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=AD=A3=E5=88=99=E8=A1=A8=E8=BE=BE=E5=BC=8F=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E8=BF=94=E5=9B=9E-1=EF=BC=8Csize=5Ft=E9=80=A0?= =?UTF-8?q?=E6=88=90=E6=95=B0=E6=8D=AE=E5=8F=8D=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/business/pangu-http/src/pangu_http.cpp | 42 ++++++++++++++++--- .../pangu-http/src/pattern_replace.cpp | 2 +- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/plugin/business/pangu-http/src/pangu_http.cpp b/plugin/business/pangu-http/src/pangu_http.cpp index e71e962..b77f37e 100644 --- a/plugin/business/pangu-http/src/pangu_http.cpp +++ b/plugin/business/pangu-http/src/pangu_http.cpp @@ -1412,7 +1412,8 @@ void http_replace(const struct tfe_stream * stream, const struct tfe_http_sessio rewrite_sz = 0; if (tfe_http_in_response(events) && in_resp_spec->content_type != NULL - && strstr(in_resp_spec->content_type, "charset=utf-8")) + && (strstr(in_resp_spec->content_type, "charset=utf-8") || + (strstr(in_resp_spec->content_type, "charset=UTF-8")))) { options = 1; } @@ -2313,6 +2314,36 @@ void pangu_on_http_begin(const struct tfe_stream * stream, return; } +static inline int ctx_actually_replaced(struct pangu_http_ctx * ctx) +{ + + if(ctx->action == PG_ACTION_MANIPULATE && + ctx->param->action == MA_ACTION_REPLACE && + ctx->n_enforce==1 && ctx->rep_ctx->actually_replaced==0) + { + return 1; + } + else + { + return 0; + } +} + +static inline int ctx_actually_inserted(struct pangu_http_ctx * ctx) +{ + + if(ctx->action == PG_ACTION_MANIPULATE && + ctx->param->action == MA_ACTION_INSERT && + ctx->n_enforce==1 && ctx->ins_ctx->actually_replaced==0) + { + return 1; + } + else + { + return 0; + } +} + void pangu_on_http_end(const struct tfe_stream * stream, const struct tfe_http_session * session, unsigned int thread_id, void ** pme) { @@ -2342,10 +2373,11 @@ void pangu_on_http_end(const struct tfe_stream * stream, } struct pangu_log log_msg = {.stream=stream, .http=session, .result=ctx->enforce_rules, .result_num=ctx->n_enforce, .req_body= ctx->log_req_body, .resp_body=ctx->log_resp_body}; - if (ctx->action != PG_ACTION_NONE&& - !(ctx->action == PG_ACTION_MANIPULATE && - ctx->param->action == MA_ACTION_REPLACE && - ctx->n_enforce==1 && ctx->rep_ctx->actually_replaced==0)) + + if ((ctx->action != PG_ACTION_NONE&& + !(ctx_actually_replaced(ctx))) || + (ctx->action != PG_ACTION_NONE&& + !(ctx_actually_inserted(ctx)))) { ret=pangu_send_log(g_pangu_rt->send_logger, &log_msg); ATOMIC_ADD(&(g_pangu_rt->stat_val[STAT_LOG_NUM]), ret); diff --git a/plugin/business/pangu-http/src/pattern_replace.cpp b/plugin/business/pangu-http/src/pattern_replace.cpp index ea910c5..9e54bae 100644 --- a/plugin/business/pangu-http/src/pattern_replace.cpp +++ b/plugin/business/pangu-http/src/pattern_replace.cpp @@ -202,7 +202,7 @@ size_t replace_string(const char * in, size_t in_sz, const struct replace_rule * pcre2_code *re = pcre2_compile(pattern, strlen(zone->find), pcre2_options, &error, &erroffset, 0); if (!re) - return -1; + return 0; pcre2_jit_compile(re, PCRE2_JIT_COMPLETE);