Skip to content

Commit

Permalink
Merge pull request grpc#1025 from tatsuhiro-t/use-host-if-authority-n…
Browse files Browse the repository at this point in the history
…ot-available

Use "host" header field if ":authority" is not present
  • Loading branch information
dklempner committed Mar 18, 2015
2 parents 7370136 + 229000f commit d2773a9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/core/channel/http_server_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit d2773a9

Please sign in to comment.