aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/surface/channel.c
diff options
context:
space:
mode:
authorGravatar Alistair Veitch <aveitch@google.com>2015-08-28 14:35:49 -0700
committerGravatar Alistair Veitch <aveitch@google.com>2015-08-28 14:35:49 -0700
commitbff9cf52ed6407862ce96ddfdcd8e97e56cdc520 (patch)
treeadcefb4d7740776b4e44a57336308c31dc0ef099 /src/core/surface/channel.c
parent6afe53f2360a20a4d3abda60cfdde576c29b9857 (diff)
parent808e5ae95f2fba44d2da925e8da0eaa5ce5c6585 (diff)
Merge branch 'master' into tracing_api
Diffstat (limited to 'src/core/surface/channel.c')
-rw-r--r--src/core/surface/channel.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/core/surface/channel.c b/src/core/surface/channel.c
index e50251566d..586402e21c 100644
--- a/src/core/surface/channel.c
+++ b/src/core/surface/channel.c
@@ -40,6 +40,7 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
+#include "src/core/client_config/resolver_registry.h"
#include "src/core/iomgr/iomgr.h"
#include "src/core/support/string.h"
#include "src/core/surface/call.h"
@@ -70,6 +71,7 @@ struct grpc_channel {
grpc_mdstr *grpc_message_string;
grpc_mdstr *path_string;
grpc_mdstr *authority_string;
+ grpc_mdelem *default_authority;
/** mdelem for grpc-status: 0 thru grpc-status: 2 */
grpc_mdelem *grpc_status_elem[NUM_CACHED_STATUS_ELEMS];
@@ -134,10 +136,47 @@ grpc_channel *grpc_channel_create_from_filters(
} else {
channel->max_message_length = args->args[i].value.integer;
}
+ } else if (0 == strcmp(args->args[i].key, GRPC_ARG_DEFAULT_AUTHORITY)) {
+ if (args->args[i].type != GRPC_ARG_STRING) {
+ gpr_log(GPR_ERROR, "%s: must be an string",
+ GRPC_ARG_DEFAULT_AUTHORITY);
+ } else {
+ if (channel->default_authority) {
+ /* setting this takes precedence over anything else */
+ GRPC_MDELEM_UNREF(channel->default_authority);
+ }
+ channel->default_authority = grpc_mdelem_from_strings(
+ mdctx, ":authority", args->args[i].value.string);
+ }
+ } else if (0 ==
+ strcmp(args->args[i].key, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)) {
+ if (args->args[i].type != GRPC_ARG_STRING) {
+ gpr_log(GPR_ERROR, "%s: must be an string",
+ GRPC_SSL_TARGET_NAME_OVERRIDE_ARG);
+ } else {
+ if (channel->default_authority) {
+ /* other ways of setting this (notably ssl) take precedence */
+ gpr_log(GPR_ERROR, "%s: default host already set some other way",
+ GRPC_ARG_DEFAULT_AUTHORITY);
+ } else {
+ channel->default_authority = grpc_mdelem_from_strings(
+ mdctx, ":authority", args->args[i].value.string);
+ }
+ }
}
}
}
+ if (channel->is_client && channel->default_authority == NULL &&
+ target != NULL) {
+ char *default_authority = grpc_get_default_authority(target);
+ if (default_authority) {
+ channel->default_authority = grpc_mdelem_from_strings(
+ channel->metadata_context, ":authority", default_authority);
+ }
+ gpr_free(default_authority);
+ }
+
grpc_channel_stack_init(filters, num_filters, channel, args,
channel->metadata_context,
CHANNEL_STACK_FROM_CHANNEL(channel));
@@ -161,6 +200,8 @@ static grpc_call *grpc_channel_create_call_internal(
send_metadata[num_metadata++] = path_mdelem;
if (authority_mdelem != NULL) {
send_metadata[num_metadata++] = authority_mdelem;
+ } else if (channel->default_authority != NULL) {
+ send_metadata[num_metadata++] = GRPC_MDELEM_REF(channel->default_authority);
}
return grpc_call_create(channel, parent_call, propagation_mask, cq, NULL,
@@ -251,6 +292,9 @@ static void destroy_channel(void *p, int ok) {
}
gpr_free(rc);
}
+ if (channel->default_authority != NULL) {
+ GRPC_MDELEM_UNREF(channel->default_authority);
+ }
grpc_mdctx_unref(channel->metadata_context);
gpr_mu_destroy(&channel->registered_call_mu);
gpr_free(channel->target);