整理 http/http2 公共的 header 字段,存储到 tfe_http.cpp 文件中

This commit is contained in:
luwenpeng
2019-09-16 11:37:18 +08:00
parent 4b0235d199
commit de16d2da87
6 changed files with 65 additions and 84 deletions

View File

@@ -35,6 +35,50 @@ Http2Plugin *http2_plugin()
return &g_http2_plugin;
}
int
http2_header_str_to_val(const char *str, const char * map[], unsigned int map_size)
{
for (unsigned int i = 0; i < map_size; i++)
{
if (!strncasecmp(str, map[i], strlen(map[i])))
{
return i;
}
}
// in http [TFE_HTTP_UNKNOWN_FIELD] = NULL; [TFE_HTTP_HOST] = "Host",
// in http2 [TFE_HTTP_UNKNOWN_FIELD] = "unknown"; [TFE_HTTP_HOST] = ":authority"
if (!strncasecmp(str, ":authority", strlen(":authority")))
{
return TFE_HTTP_HOST;
} else {
return TFE_HTTP_UNKNOWN_FIELD;
}
}
const char*
http2_header_val_to_str(unsigned int val, const char * map[], unsigned int map_size)
{
const static char * host = ":authority";
const static char * unknown = "unknown";
if (val < map_size && val != TFE_HTTP_HOST && val != TFE_HTTP_UNKNOWN_FIELD)
{
return map[val];
}
// in http [TFE_HTTP_UNKNOWN_FIELD] = NULL; [TFE_HTTP_HOST] = "Host",
// in http2 [TFE_HTTP_UNKNOWN_FIELD] = "unknown"; [TFE_HTTP_HOST] = ":authority"
if (val == TFE_HTTP_HOST)
{
return host;
}
else
{
return unknown;
}
}
const char *
try_val_to_str_idx(const unsigned int val, const struct value_string *vs, int *idx)
{