aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/core/security/security_context.c17
-rw-r--r--src/core/security/security_context.h2
-rw-r--r--src/core/surface/secure_channel_create.c3
3 files changed, 16 insertions, 6 deletions
diff --git a/src/core/security/security_context.c b/src/core/security/security_context.c
index e180cad52b..08137803a3 100644
--- a/src/core/security/security_context.c
+++ b/src/core/security/security_context.c
@@ -165,6 +165,16 @@ static int check_request_metadata_creds(grpc_credentials *creds) {
return 1;
}
+static grpc_mdctx *get_or_create_mdctx(grpc_credentials *creds) {
+ grpc_mdctx *mdctx = grpc_credentials_get_metadata_context(creds);
+ if (mdctx == NULL) {
+ mdctx = grpc_mdctx_create();
+ } else {
+ grpc_mdctx_ref(mdctx);
+ }
+ return mdctx;
+}
+
/* -- Fake implementation. -- */
typedef struct {
@@ -626,7 +636,8 @@ grpc_channel *grpc_ssl_channel_create(grpc_credentials *ssl_creds,
arg.key = GRPC_ARG_HTTP2_SCHEME;
arg.value.string = "https";
new_args = grpc_channel_args_copy_and_add(args, &arg);
- channel = grpc_secure_channel_create_internal(target, new_args, ctx);
+ channel = grpc_secure_channel_create_internal(
+ target, new_args, ctx, get_or_create_mdctx(request_metadata_creds));
grpc_security_context_unref(&ctx->base);
grpc_channel_args_destroy(new_args);
return channel;
@@ -637,8 +648,8 @@ grpc_channel *grpc_fake_transport_security_channel_create(
const char *target, const grpc_channel_args *args) {
grpc_channel_security_context *ctx =
grpc_fake_channel_security_context_create(request_metadata_creds, 1);
- grpc_channel *channel =
- grpc_secure_channel_create_internal(target, args, ctx);
+ grpc_channel *channel = grpc_secure_channel_create_internal(
+ target, args, ctx, get_or_create_mdctx(request_metadata_creds));
grpc_security_context_unref(&ctx->base);
return channel;
}
diff --git a/src/core/security/security_context.h b/src/core/security/security_context.h
index 2b4e38f3ea..8e7ba34cac 100644
--- a/src/core/security/security_context.h
+++ b/src/core/security/security_context.h
@@ -190,7 +190,7 @@ grpc_channel *grpc_fake_transport_security_channel_create(
grpc_channel *grpc_secure_channel_create_internal(
const char *target, const grpc_channel_args *args,
- grpc_channel_security_context *ctx);
+ grpc_channel_security_context *ctx, grpc_mdctx *mdctx);
typedef grpc_channel *(*grpc_secure_channel_factory_func)(
grpc_credentials *transport_security_creds,
diff --git a/src/core/surface/secure_channel_create.c b/src/core/surface/secure_channel_create.c
index 8e56868d42..96b2fe04fa 100644
--- a/src/core/surface/secure_channel_create.c
+++ b/src/core/surface/secure_channel_create.c
@@ -205,12 +205,11 @@ static grpc_transport_setup_result complete_setup(void *channel_stack,
- perform handshakes */
grpc_channel *grpc_secure_channel_create_internal(
const char *target, const grpc_channel_args *args,
- grpc_channel_security_context *context) {
+ grpc_channel_security_context *context, grpc_mdctx *mdctx) {
setup *s;
grpc_channel *channel;
grpc_arg context_arg;
grpc_channel_args *args_copy;
- grpc_mdctx *mdctx = grpc_mdctx_create();
#define MAX_FILTERS 3
const grpc_channel_filter *filters[MAX_FILTERS];
int n = 0;