初步调通HTTP重定向业务
* 增加HTTP Status标准化定义及辅助函数; * 增加HTTP解析层发送应答的功能 * 修正了Pangu HTTP实现导致段错误的一系列问题。
This commit is contained in:
@@ -768,10 +768,13 @@ static void http_redirect(const struct tfe_http_session * session, enum tfe_http
|
||||
{
|
||||
int resp_code = 0, ret = 0;
|
||||
char * url = NULL;
|
||||
|
||||
struct tfe_http_half * response = NULL;
|
||||
struct tfe_http_session * to_write = NULL;
|
||||
|
||||
url = ALLOC(char, ctx->enforce_rules[0].serv_def_len);
|
||||
ret = sscanf(ctx->enforce_para, "code=%d%[^;];url=%*[^;];", &resp_code, url);
|
||||
ret = sscanf(ctx->enforce_para, "code=%d;url=%[^;]", &resp_code, url);
|
||||
|
||||
if (ret != 2)
|
||||
{
|
||||
TFE_LOG_ERROR(g_pangu_rt->local_logger, "Invalid redirect rule %d paramter %s",
|
||||
@@ -780,10 +783,16 @@ static void http_redirect(const struct tfe_http_session * session, enum tfe_http
|
||||
}
|
||||
|
||||
to_write = tfe_http_session_allow_write(session);
|
||||
if (to_write == NULL)
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
response = tfe_http_session_response_create(to_write, resp_code);
|
||||
_wrap_std_field_write(response, TFE_HTTP_LOCATION, url);
|
||||
|
||||
tfe_http_session_response_set(to_write, response);
|
||||
response = NULL;
|
||||
tfe_http_session_detach(session);
|
||||
|
||||
error_out:
|
||||
free(url);
|
||||
@@ -862,16 +871,24 @@ enum pangu_action http_scan(const struct tfe_http_session * session, enum tfe_ht
|
||||
Maat_stream_scan_string_end(&(ctx->sp));
|
||||
ctx->sp = NULL;
|
||||
}
|
||||
|
||||
if (hit_cnt > 0)
|
||||
{
|
||||
ctx->action = decide_ctrl_action(result, hit_cnt, &ctx->enforce_rules, &ctx->n_enforce);
|
||||
if (ctx->enforce_rules[0].serv_def_len > MAX_SERVICE_DEFINE_LEN)
|
||||
size_t __serv_def_len = (size_t)ctx->enforce_rules[0].serv_def_len;
|
||||
ctx->enforce_para = ALLOC(char, __serv_def_len);
|
||||
|
||||
if (__serv_def_len > MAX_SERVICE_DEFINE_LEN)
|
||||
{
|
||||
ctx->enforce_para = ALLOC(char, ctx->enforce_rules->serv_def_len);
|
||||
read_rule_ret = Maat_read_rule(g_pangu_rt->maat, ctx->enforce_rules + 0,
|
||||
MAAT_RULE_SERV_DEFINE, ctx->enforce_para, ctx->enforce_rules[0].serv_def_len);
|
||||
read_rule_ret = Maat_read_rule(g_pangu_rt->maat, &ctx->enforce_rules[0], MAAT_RULE_SERV_DEFINE,
|
||||
ctx->enforce_para, ctx->enforce_rules[0].serv_def_len);
|
||||
assert(read_rule_ret == ctx->enforce_rules[0].serv_def_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(ctx->enforce_para, ctx->enforce_rules[0].service_defined);
|
||||
}
|
||||
|
||||
if (hit_cnt > 1)
|
||||
{
|
||||
p = buff;
|
||||
@@ -879,11 +896,13 @@ enum pangu_action http_scan(const struct tfe_http_session * session, enum tfe_ht
|
||||
{
|
||||
p += snprintf(p, sizeof(buff) - (p - buff), "%d:", result[i].config_id);
|
||||
}
|
||||
|
||||
*p = '\0';
|
||||
TFE_LOG_INFO(g_pangu_rt->local_logger, "Multiple rules matched: url=%s num=%lu ids=%s execute=%d.",
|
||||
session->req->req_spec.url, hit_cnt, buff, ctx->enforce_rules[0].config_id);
|
||||
}
|
||||
}
|
||||
|
||||
return ctx->action;
|
||||
}
|
||||
|
||||
@@ -949,6 +968,7 @@ Re_Enter:
|
||||
case PG_ACTION_REJECT: http_reject(session, events, ctx);
|
||||
break;
|
||||
case PG_ACTION_REDIRECT: http_redirect(session, events, ctx);
|
||||
break;
|
||||
case PG_ACTION_REPLACE: http_replace(stream, session, events, body_frag, frag_size, ctx);
|
||||
break;
|
||||
case PG_ACTION_WHITELIST: tfe_http_session_detach(session);
|
||||
|
||||
Reference in New Issue
Block a user