diff options
author | David Klempner <klempner@google.com> | 2015-03-17 17:23:53 -0700 |
---|---|---|
committer | David Klempner <klempner@google.com> | 2015-03-17 17:23:53 -0700 |
commit | d2773a9bd8ef3f1951f0b338b90837bb8a656860 (patch) | |
tree | 9297c5abee40212465e7560457b63e54dc9d2e56 /src/core | |
parent | 7370136427bb974ece569885c4e3f526d310a6ef (diff) | |
parent | 229000fd2b55ea426461c88bc4889297cd1baa80 (diff) |
Merge pull request #1025 from tatsuhiro-t/use-host-if-authority-not-available
Use "host" header field if ":authority" is not present
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/channel/http_server_filter.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/core/channel/http_server_filter.c b/src/core/channel/http_server_filter.c index d1616a3450..f565cbf3ae 100644 --- a/src/core/channel/http_server_filter.c +++ b/src/core/channel/http_server_filter.c @@ -66,6 +66,10 @@ typedef struct channel_data { grpc_mdelem *status_ok; grpc_mdelem *status_not_found; grpc_mdstr *path_key; + grpc_mdstr *authority_key; + grpc_mdstr *host_key; + + grpc_mdctx *mdctx; size_t gettable_count; gettable *gettables; @@ -181,6 +185,15 @@ static void call_op(grpc_call_element *elem, grpc_call_element *from_elem, } calld->path = op->data.metadata; op->done_cb(op->user_data, GRPC_OP_OK); + } else if (op->data.metadata->key == channeld->host_key) { + /* translate host to :authority since :authority may be + omitted */ + grpc_mdelem *authority = grpc_mdelem_from_metadata_strings( + channeld->mdctx, channeld->authority_key, op->data.metadata->value); + grpc_mdelem_unref(op->data.metadata); + op->data.metadata = authority; + /* pass the event up */ + grpc_call_next_op(elem, op); } else { /* pass the event up */ grpc_call_next_op(elem, op); @@ -305,9 +318,13 @@ static void init_channel_elem(grpc_channel_element *elem, channeld->https_scheme = grpc_mdelem_from_strings(mdctx, ":scheme", "https"); channeld->grpc_scheme = grpc_mdelem_from_strings(mdctx, ":scheme", "grpc"); channeld->path_key = grpc_mdstr_from_string(mdctx, ":path"); + channeld->authority_key = grpc_mdstr_from_string(mdctx, ":authority"); + channeld->host_key = grpc_mdstr_from_string(mdctx, "host"); channeld->content_type = grpc_mdelem_from_strings(mdctx, "content-type", "application/grpc"); + channeld->mdctx = mdctx; + /* initialize http download support */ channeld->gettable_count = 0; channeld->gettables = NULL; @@ -357,6 +374,8 @@ static void destroy_channel_elem(grpc_channel_element *elem) { grpc_mdelem_unref(channeld->grpc_scheme); grpc_mdelem_unref(channeld->content_type); grpc_mdstr_unref(channeld->path_key); + grpc_mdstr_unref(channeld->authority_key); + grpc_mdstr_unref(channeld->host_key); } const grpc_channel_filter grpc_http_server_filter = { |