Use metadata batch callouts in client_auth_filter.

pull/14675/head
Mark D. Roth 7 years ago
parent ec154f6f2d
commit ecc865124c
  1. 36
      src/core/lib/security/transport/client_auth_filter.cc

@ -45,8 +45,6 @@ struct call_data {
grpc_call_stack* owning_call; grpc_call_stack* owning_call;
grpc_call_combiner* call_combiner; grpc_call_combiner* call_combiner;
grpc_call_credentials* creds; grpc_call_credentials* creds;
bool have_host;
bool have_method;
grpc_slice host; grpc_slice host;
grpc_slice method; grpc_slice method;
/* pollset{_set} bound to this call; if we need to make external /* pollset{_set} bound to this call; if we need to make external
@ -294,27 +292,15 @@ static void auth_start_transport_stream_op_batch(
} }
if (batch->send_initial_metadata) { if (batch->send_initial_metadata) {
for (grpc_linked_mdelem* l = batch->payload->send_initial_metadata grpc_metadata_batch* metadata =
.send_initial_metadata->list.head; batch->payload->send_initial_metadata.send_initial_metadata;
l != nullptr; l = l->next) { if (metadata->idx.named.path != nullptr) {
grpc_mdelem md = l->md; calld->method =
/* Pointer comparison is OK for md_elems created from the same context. grpc_slice_ref_internal(GRPC_MDVALUE(metadata->idx.named.path->md));
*/
if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_AUTHORITY)) {
if (calld->have_host) {
grpc_slice_unref_internal(calld->host);
}
calld->host = grpc_slice_ref_internal(GRPC_MDVALUE(md));
calld->have_host = true;
} else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_PATH)) {
if (calld->have_method) {
grpc_slice_unref_internal(calld->method);
}
calld->method = grpc_slice_ref_internal(GRPC_MDVALUE(md));
calld->have_method = true;
}
} }
if (calld->have_host) { if (metadata->idx.named.authority != nullptr) {
calld->host = grpc_slice_ref_internal(
GRPC_MDVALUE(metadata->idx.named.authority->md));
batch->handler_private.extra_arg = elem; batch->handler_private.extra_arg = elem;
GRPC_CALL_STACK_REF(calld->owning_call, "check_call_host"); GRPC_CALL_STACK_REF(calld->owning_call, "check_call_host");
GRPC_CLOSURE_INIT(&calld->async_result_closure, on_host_checked, batch, GRPC_CLOSURE_INIT(&calld->async_result_closure, on_host_checked, batch,
@ -351,6 +337,8 @@ static grpc_error* init_call_elem(grpc_call_element* elem,
call_data* calld = static_cast<call_data*>(elem->call_data); call_data* calld = static_cast<call_data*>(elem->call_data);
calld->owning_call = args->call_stack; calld->owning_call = args->call_stack;
calld->call_combiner = args->call_combiner; calld->call_combiner = args->call_combiner;
calld->host = grpc_empty_slice();
calld->method = grpc_empty_slice();
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
} }
@ -367,12 +355,8 @@ static void destroy_call_elem(grpc_call_element* elem,
call_data* calld = static_cast<call_data*>(elem->call_data); call_data* calld = static_cast<call_data*>(elem->call_data);
grpc_credentials_mdelem_array_destroy(&calld->md_array); grpc_credentials_mdelem_array_destroy(&calld->md_array);
grpc_call_credentials_unref(calld->creds); grpc_call_credentials_unref(calld->creds);
if (calld->have_host) {
grpc_slice_unref_internal(calld->host); grpc_slice_unref_internal(calld->host);
}
if (calld->have_method) {
grpc_slice_unref_internal(calld->method); grpc_slice_unref_internal(calld->method);
}
grpc_auth_metadata_context_reset(&calld->auth_md_context); grpc_auth_metadata_context_reset(&calld->auth_md_context);
} }

Loading…
Cancel
Save