diff options
author | Mark D. Roth <roth@google.com> | 2016-04-27 07:17:58 -0700 |
---|---|---|
committer | Mark D. Roth <roth@google.com> | 2016-04-27 07:17:58 -0700 |
commit | 640d71dda90fee3dbb66f1b50c9b42058d063244 (patch) | |
tree | 5fca8a961d5fbb5ddf0712b1ef7017535b4c2abe /src/core/lib/channel | |
parent | c5b1eef8b1e6d56a9f3c25962d815ae6579c78ee (diff) |
Use cpp macros for the "application/grpc" string and its length.
Also remove unnecessary strlen() call.
Diffstat (limited to 'src/core/lib/channel')
-rw-r--r-- | src/core/lib/channel/http_server_filter.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index ad3462bff4..192783f4ed 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -39,6 +39,9 @@ #include "src/core/lib/profiling/timers.h" #include "src/core/lib/transport/static_metadata.h" +#define EXPECTED_CONTENT_TYPE "application/grpc" +#define EXPECTED_CONTENT_TYPE_LENGTH sizeof(EXPECTED_CONTENT_TYPE) - 1 + typedef struct call_data { uint8_t seen_path; uint8_t seen_method; @@ -93,9 +96,10 @@ static grpc_mdelem *server_filter(void *user_data, grpc_mdelem *md) { return NULL; } else if (md->key == GRPC_MDSTR_CONTENT_TYPE) { const char* value_str = grpc_mdstr_as_c_string(md->value); - if (strncmp(value_str, "application/grpc", 16) == 0 && - (strlen(value_str) == 16 || - value_str[16] == '+' || value_str[16] == ';')) { + if (strncmp(value_str, EXPECTED_CONTENT_TYPE, + EXPECTED_CONTENT_TYPE_LENGTH) == 0 && + (value_str[EXPECTED_CONTENT_TYPE_LENGTH] == '+' || + value_str[EXPECTED_CONTENT_TYPE_LENGTH] == ';')) { /* Although the C implementation doesn't (currently) generate them, any custom +-suffix is explicitly valid. */ /* TODO(klempner): We should consider preallocating common values such |