aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2015-07-15 13:38:57 -0700
committerGravatar Craig Tiller <ctiller@google.com>2015-07-15 13:38:57 -0700
commitded3f697167440bc9a298286c918c6d8c9553bd9 (patch)
treed6f9e2c46cfd73d8b13f071a35a10c8ee63d2731
parent5a9674c0e7683f60bdd55f938e57dceb0a85a9e8 (diff)
parent94d6225ae7fa587f787fcbfdbd3ab8a365d1bb04 (diff)
Merge pull request #2442 from yang-g/authcontext_lazy_create_at_server
Create server side auth context lazily
-rw-r--r--include/grpc++/server_context.h6
-rw-r--r--src/cpp/server/server_context.cc7
2 files changed, 9 insertions, 4 deletions
diff --git a/include/grpc++/server_context.h b/include/grpc++/server_context.h
index a4ee986df1..2123d03291 100644
--- a/include/grpc++/server_context.h
+++ b/include/grpc++/server_context.h
@@ -99,9 +99,7 @@ class ServerContext {
return client_metadata_;
}
- std::shared_ptr<const AuthContext> auth_context() const {
- return auth_context_;
- }
+ std::shared_ptr<const AuthContext> auth_context() const;
private:
friend class ::grpc::Server;
@@ -147,7 +145,7 @@ class ServerContext {
grpc_call* call_;
CompletionQueue* cq_;
bool sent_initial_metadata_;
- std::shared_ptr<const AuthContext> auth_context_;
+ mutable std::shared_ptr<const AuthContext> auth_context_;
std::multimap<grpc::string, grpc::string> client_metadata_;
std::multimap<grpc::string, grpc::string> initial_metadata_;
std::multimap<grpc::string, grpc::string> trailing_metadata_;
diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc
index 1bb3a8bcc4..0be77138d1 100644
--- a/src/cpp/server/server_context.cc
+++ b/src/cpp/server/server_context.cc
@@ -153,4 +153,11 @@ void ServerContext::set_call(grpc_call* call) {
auth_context_ = CreateAuthContext(call);
}
+std::shared_ptr<const AuthContext> ServerContext::auth_context() const {
+ if (auth_context_.get() == nullptr) {
+ auth_context_ = CreateAuthContext(call_);
+ }
+ return auth_context_;
+}
+
} // namespace grpc