diff options
| author | luwenpeng <[email protected]> | 2019-09-16 11:37:18 +0800 |
|---|---|---|
| committer | luwenpeng <[email protected]> | 2019-09-16 14:27:11 +0800 |
| commit | de16d2da87d8c7d141527c06985bdc6eeaf11b84 (patch) | |
| tree | 1a4de92d057548a747f3c36d67e365d0b5f21fff /plugin/protocol/http2/src/http2_common.cpp | |
| parent | 4b0235d1999e200437939688e0490d575a3da5cc (diff) | |
整理 http/http2 公共的 header 字段,存储到 tfe_http.cpp 文件中
Diffstat (limited to 'plugin/protocol/http2/src/http2_common.cpp')
| -rw-r--r-- | plugin/protocol/http2/src/http2_common.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/plugin/protocol/http2/src/http2_common.cpp b/plugin/protocol/http2/src/http2_common.cpp index 2847ce5..b59f52b 100644 --- a/plugin/protocol/http2/src/http2_common.cpp +++ b/plugin/protocol/http2/src/http2_common.cpp @@ -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) { |
