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);