From cdc0d03b2d868027f7b0158422885d58cc7b17ab Mon Sep 17 00:00:00 2001
From: Muxi Yan <mxyan@google.com>
Date: Tue, 9 May 2017 16:04:10 -0700
Subject: [PATCH] Add EnableWorkaround API to enable server workarounds

---
 include/grpc++/server_builder.h  |  6 ++++++
 src/cpp/server/server_builder.cc | 15 +++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/include/grpc++/server_builder.h b/include/grpc++/server_builder.h
index 7ac23349c8..7d34592dbb 100644
--- a/include/grpc++/server_builder.h
+++ b/include/grpc++/server_builder.h
@@ -184,6 +184,11 @@ class ServerBuilder {
   static void InternalAddPluginFactory(
       std::unique_ptr<ServerBuilderPlugin> (*CreatePlugin)());
 
+  /// Enable a server workaround. Do not use unless you know what the workaround
+  /// does. For explanation and detailed descriptions of workarounds, see
+  /// docs/workarounds.md.
+  ServerBuilder& EnableWorkaround(uint32_t id);
+
  private:
   friend class ::grpc::testing::ServerBuilderPluginTest;
 
@@ -226,6 +231,7 @@ class ServerBuilder {
   std::vector<std::unique_ptr<ServerBuilderOption>> options_;
   std::vector<std::unique_ptr<NamedService>> services_;
   std::vector<Port> ports_;
+  std::vector<const char *> enabled_workarounds_;
 
   SyncServerSettings sync_server_settings_;
 
diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc
index 2ead048a1f..67a7846da5 100644
--- a/src/cpp/server/server_builder.cc
+++ b/src/cpp/server/server_builder.cc
@@ -39,6 +39,7 @@
 #include <grpc/support/cpu.h>
 #include <grpc/support/log.h>
 #include <grpc/support/useful.h>
+#include <grpc/support/workaround_list.h>
 
 #include "src/cpp/server/thread_pool_interface.h"
 
@@ -198,6 +199,10 @@ std::unique_ptr<Server> ServerBuilder::BuildAndStart() {
     args.SetInt(GRPC_ARG_MAX_SEND_MESSAGE_LENGTH, max_send_message_size_);
   }
 
+  for (auto workaround : enabled_workarounds_) {
+    args.SetInt(workaround, 1);
+  }
+
   args.SetInt(GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET,
               enabled_compression_algorithms_bitset_);
   if (maybe_default_compression_level_.is_set) {
@@ -358,4 +363,14 @@ void ServerBuilder::InternalAddPluginFactory(
   (*g_plugin_factory_list).push_back(CreatePlugin);
 }
 
+void ServerBuilder::EnableWorkaround(uint32_t id) {
+  switch (id) {
+    case GRPC_WORKAROUND_ID_CRONET_COMPRESSION:
+      enabled_workarounds_.push_back(GRPC_ARG_WORKAROUND_CRONET_COMPRESSION);
+      break;
+    default:
+      gpr_log(GPR_ERROR, "Workaround %u is not exist or obsolete.", id);
+  }
+}
+
 }  // namespace grpc
-- 
GitLab