TSG-7141 修复非格式日志部分下载失败问题

修复重定向指定用户自定义域无法替换问题
This commit is contained in:
fengweihao
2021-07-23 15:55:42 +08:00
parent d18b647ec5
commit 9745251b2a
5 changed files with 19 additions and 16 deletions

View File

@@ -473,7 +473,7 @@ int cache_evbase_upload_once_evbuf(struct cache_evbase_instance *instance, struc
buffer->ctx_asyn = ctx_asyn;
buffer->cmd_type = CACHE_ASYN_UPLOAD_ONCE_EVBUF;
buffer->evbuf = evbuffer_new();
evbuffer_add_buffer(buffer->evbuf, evbuf);
evbuffer_add_buffer_reference(buffer->evbuf, evbuf);
if(iothread_notify_event(instance->notify_sendfd, &buffer, sizeof(void *), 2) != sizeof(void *))
{

View File

@@ -114,7 +114,7 @@ static size_t curl_put_multipart_send_cb(void *ptr, size_t size, size_t count, v
static int http_put_bodypart_request_evbuf(struct tango_cache_ctx *ctx, bool full)
{
UNUSED CURLMcode rc;
char minio_url[256], buffer[256];
char minio_url[256]={0}, buffer[256]={0};
if(NULL == (ctx->curl=curl_easy_init()))
{

View File

@@ -1532,7 +1532,7 @@ static void http_get_client_id(const struct tfe_stream * stream, char *replace_r
tfe_stream_addr_str_split((char *)stream->str_stream_info, &sip, &sport, &dip, &dport);
snprintf(replace_regex, TFE_SYMBOL_MAX, "%s=%s", "source_ip", sip);
snprintf(replace_regex, TFE_SYMBOL_MAX, "%s", sip);
}
static void http_get_subscriber_id(const struct tfe_stream * stream, char *replace_regex)
@@ -1549,7 +1549,7 @@ static void http_get_subscriber_id(const struct tfe_stream * stream, char *repla
TFE_LOG_ERROR(g_pangu_rt->local_logger, "fetch src sub id from cmsg failed, ret: %d addr: %s", ret, stream->str_stream_info);
}
}
snprintf(replace_regex, TFE_SYMBOL_MAX, "%s=%s", "user_id", source_subscribe_id);
snprintf(replace_regex, TFE_SYMBOL_MAX, "%s", source_subscribe_id);
}
static int http_decoder_url(const struct tfe_stream * stream, char *rd_url, int profile_id, char **rewrite_uri)
@@ -1558,7 +1558,7 @@ static int http_decoder_url(const struct tfe_stream * stream, char *rd_url, int
char replace_with[TFE_SYMBOL_MAX]={0};
struct replace_rule *rule;
if(strstr(rd_url, "policy_id")==NULL && strstr(rd_url, "user_id")==NULL && strstr(rd_url, "source_ip")==NULL)
if(strstr(rd_url, "tsg_policy_id")==NULL && strstr(rd_url, "tsg_subscriber_id")==NULL && strstr(rd_url, "tsg_client_ip")==NULL)
{
return 0;
}
@@ -1566,21 +1566,21 @@ static int http_decoder_url(const struct tfe_stream * stream, char *rd_url, int
rule = ALLOC(struct replace_rule, 3);
n_rule=0;
rule[n_rule].zone = kZoneRequestUri;
rule[n_rule].find = tfe_strdup("policy_id={{tsg_policy_id}}");
snprintf(replace_with, TFE_SYMBOL_MAX, "policy_id=%d", profile_id);
rule[n_rule].find = tfe_strdup("{{tsg_policy_id}}");
snprintf(replace_with, TFE_SYMBOL_MAX, "%d", profile_id);
rule[n_rule].replace_with = tfe_strdup(replace_with);
n_rule=1;
memset(replace_with, TFE_SYMBOL_MAX, 0);
rule[n_rule].zone = kZoneRequestUri;
rule[n_rule].find = tfe_strdup("user_id={{tsg_subscriber_id}}");
rule[n_rule].find = tfe_strdup("{{tsg_subscriber_id}}");
http_get_subscriber_id(stream, replace_with);
rule[n_rule].replace_with = tfe_strdup(replace_with);
n_rule=2;
memset(replace_with, TFE_SYMBOL_MAX, 0);
rule[n_rule].zone = kZoneRequestUri;
rule[n_rule].find = tfe_strdup("source_ip={{tsg_client_ip}}");
rule[n_rule].find = tfe_strdup("{{tsg_client_ip}}");
http_get_client_id(stream, replace_with);
rule[n_rule].replace_with = tfe_strdup(replace_with);

View File

@@ -284,6 +284,9 @@ int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg)
}
if(log_msg->resp_body!=NULL)
{
memset(log_file_upload_path, 0, sizeof(log_file_upload_path));
memset(cont_type_whole, 0, sizeof(cont_type_whole));
memset(&meta, 0, sizeof(meta));
asprintf(&log_file_key, "%s.respbody", http->req->req_spec.url);
meta.url=log_file_key;

View File

@@ -186,7 +186,7 @@ TEST(PatternReplace, UrlReplace)
const char *rd_url = "http://www.example.com/query?pageid=12345&policy_id={{tsg_policy_id}}&user_id={{tsg_subscriber_id}}&source_ip={{tsg_client_ip}}";
if(strstr(rd_url, "policy_id")==NULL && strstr(rd_url, "user_id")==NULL && strstr(rd_url, "source_ip")==NULL)
if(strstr(rd_url, "tsg_policy_id")==NULL && strstr(rd_url, "tsg_subscriber_id")==NULL && strstr(rd_url, "tsg_client_ip")==NULL)
{
return;
}
@@ -194,21 +194,21 @@ TEST(PatternReplace, UrlReplace)
rule = ALLOC(struct replace_rule, 3);
n_rule=0;
rule[n_rule].zone = kZoneRequestUri;
rule[n_rule].find = tfe_strdup("policy_id={{tsg_policy_id}}");
snprintf(replace_with, TFE_SYMBOL_MAX, "policy_id=%d", 23);
rule[n_rule].find = tfe_strdup("{{tsg_policy_id}}");
snprintf(replace_with, TFE_SYMBOL_MAX, "%d", 23);
rule[n_rule].replace_with = tfe_strdup(replace_with);
n_rule=1;
memset(replace_with, TFE_SYMBOL_MAX, 0);
rule[n_rule].zone = kZoneRequestUri;
rule[n_rule].find = tfe_strdup("user_id={{tsg_subscriber_id}}");
rule[n_rule].replace_with = tfe_strdup("user_id=te&st01");
rule[n_rule].find = tfe_strdup("{{tsg_subscriber_id}}");
rule[n_rule].replace_with = tfe_strdup("te&st01");
n_rule=2;
memset(replace_with, TFE_SYMBOL_MAX, 0);
rule[n_rule].zone = kZoneRequestUri;
rule[n_rule].find = tfe_strdup("source_ip={{tsg_client_ip}}");
rule[n_rule].replace_with = tfe_strdup("source_ip=192.168.50.71");
rule[n_rule].find = tfe_strdup("{{tsg_client_ip}}");
rule[n_rule].replace_with = tfe_strdup("192.168.50.71");
size_t rewrite_uri_sz = execute_replace_rule(rd_url, strlen(rd_url), kZoneRequestUri, rule, n_rule+1, &rewrite_uri, 1);