{"action":"created","comment":{"url":"https://api.github.com/repos/lyft/envoy/pulls/comments/123783165","pull_request_review_id":46019303,"id":123783165,"diff_hunk":"@@ -0,0 +1,384 @@\n+#include \"common/grpc/transcoding_filter.h\"\n+\n+#include \"envoy/common/exception.h\"\n+#include \"envoy/http/filter.h\"\n+\n+#include \"common/common/enum_to_int.h\"\n+#include \"common/common/utility.h\"\n+#include \"common/filesystem/filesystem_impl.h\"\n+#include \"common/http/headers.h\"\n+#include \"common/http/utility.h\"\n+\n+#include \"google/api/annotations.pb.h\"\n+#include \"google/api/http.pb.h\"\n+#include \"google/protobuf/descriptor.h\"\n+#include \"google/protobuf/descriptor.pb.h\"\n+#include \"google/protobuf/util/type_resolver.h\"\n+#include \"google/protobuf/util/type_resolver_util.h\"\n+#include \"grpc_transcoding/json_request_translator.h\"\n+#include \"grpc_transcoding/response_to_json_translator.h\"\n+\n+using google::grpc::transcoding::JsonRequestTranslator;\n+using google::grpc::transcoding::RequestInfo;\n+using google::grpc::transcoding::ResponseToJsonTranslator;\n+using google::grpc::transcoding::Transcoder;\n+using google::grpc::transcoding::TranscoderInputStream;\n+using google::protobuf::DescriptorPool;\n+using google::protobuf::FileDescriptor;\n+using google::protobuf::FileDescriptorSet;\n+using google::protobuf::io::ZeroCopyInputStream;\n+using google::protobuf::util::error::Code;\n+using google::protobuf::util::Status;\n+\n+namespace Envoy {\n+namespace Grpc {\n+\n+namespace {\n+\n+const std::string kTypeUrlPrefix{\"type.googleapis.com\"};\n+\n+// Transcoder:\n+// https://github.com/grpc-ecosystem/grpc-httpjson-transcoding/blob/master/src/include/grpc_transcoding/transcoder.h\n+// implementation based on JsonRequestTranslator & ResponseToJsonTranslator\n+class TranscoderImpl : public Transcoder {\n+public:\n+  /**\n+   * Construct a transcoder implementation\n+   * @param request_translator a JsonRequestTranslator that does the request translation\n+   * @param response_translator a ResponseToJsonTranslator that does the response translation\n+   */\n+  TranscoderImpl(std::unique_ptr<JsonRequestTranslator> request_translator,\n+                 std::unique_ptr<ResponseToJsonTranslator> response_translator)\n+      : request_translator_(std::move(request_translator)),\n+        response_translator_(std::move(response_translator)),\n+        request_stream_(request_translator_->Output().CreateInputStream()),\n+        response_stream_(response_translator_->CreateInputStream()) {}\n+\n+  // Transcoder\n+  ::google::grpc::transcoding::TranscoderInputStream* RequestOutput() {\n+    return request_stream_.get();\n+  }\n+  Status RequestStatus() { return request_translator_->Output().Status(); }\n+\n+  ZeroCopyInputStream* ResponseOutput() { return response_stream_.get(); }\n+  Status ResponseStatus() { return response_translator_->Status(); }\n+\n+private:\n+  std::unique_ptr<JsonRequestTranslator> request_translator_;\n+  std::unique_ptr<ResponseToJsonTranslator> response_translator_;\n+  std::unique_ptr<TranscoderInputStream> request_stream_;\n+  std::unique_ptr<TranscoderInputStream> response_stream_;\n+};\n+\n+} // namespace\n+\n+TranscodingConfig::TranscodingConfig(const Json::Object& config) {\n+  const std::string proto_descriptor_file = config.getString(\"proto_descriptor\");\n+  FileDescriptorSet descriptor_set;\n+  if (!descriptor_set.ParseFromString(Filesystem::fileReadToEnd(proto_descriptor_file))) {\n+    throw EnvoyException(\"Unable to parse proto descriptor\");\n+  }\n+\n+  for (const auto& file : descriptor_set.file()) {\n+    if (descriptor_pool_.BuildFile(file) == nullptr) {\n+      throw EnvoyException(\"Unable to parse proto descriptor\");\n+    }\n+  }\n+\n+  // TODO(lizan): Consider factor out building PathMatcher building.\n+  google::grpc::transcoding::PathMatcherBuilder<const google::protobuf::MethodDescriptor*> pmb;\n+\n+  for (const auto& service_name : config.getStringArray(\"services\")) {\n+    auto service = descriptor_pool_.FindServiceByName(service_name);\n+    if (service == nullptr) {\n+      throw EnvoyException(\"Could not find '\" + service_name + \"' in the proto descriptor\");\n+    }\n+    for (int i = 0; i < service->method_count(); ++i) {\n+      auto method = service->method(i);\n+\n+      auto http_rule = method->options().GetExtension(google::api::http);\n+\n+      switch (http_rule.pattern_case()) {\n+      case ::google::api::HttpRule::kGet:\n+        pmb.Register(\"GET\", http_rule.get(), http_rule.body(), method);\n+        break;\n+      case ::google::api::HttpRule::kPut:\n+        pmb.Register(\"PUT\", http_rule.put(), http_rule.body(), method);\n+        break;\n+      case ::google::api::HttpRule::kPost:\n+        pmb.Register(\"POST\", http_rule.post(), http_rule.body(), method);\n+        break;\n+      case ::google::api::HttpRule::kDelete:\n+        pmb.Register(\"DELETE\", http_rule.delete_(), http_rule.body(), method);\n+        break;\n+      case ::google::api::HttpRule::kPatch:\n+        pmb.Register(\"PATCH\", http_rule.patch(), http_rule.body(), method);\n+        break;\n+      case ::google::api::HttpRule::kCustom:\n+        pmb.Register(http_rule.custom().kind(), http_rule.custom().path(), http_rule.body(),\n+                     method);\n+        break;\n+      default:\n+        break;\n+      }\n+    }\n+  }\n+\n+  path_matcher_ = pmb.Build();\n+\n+  type_helper_.reset(new google::grpc::transcoding::TypeHelper(\n+      google::protobuf::util::NewTypeResolverForDescriptorPool(kTypeUrlPrefix, &descriptor_pool_)));\n+\n+  ENVOY_LOG(debug, \"grpc_transcoding filter loaded\");","path":"source/common/grpc/transcoding_filter.cc","position":132,"original_position":132,"commit_id":"41416cdfffca73667685fa2ae0de1b391a797774","original_commit_id":"41416cdfffca73667685fa2ae0de1b391a797774","user":{"login":"mattklein123","id":6305260,"avatar_url":"https://avatars0.githubusercontent.com/u/6305260?v=3","gravatar_id":"","url":"https://api.github.com/users/mattklein123","html_url":"https://github.com/mattklein123","followers_url":"https://api.github.com/users/mattklein123/followers","following_url":"https://api.github.com/users/mattklein123/following{/other_user}","gists_url":"https://api.github.com/users/mattklein123/gists{/gist_id}","starred_url":"https://api.github.com/users/mattklein123/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattklein123/subscriptions","organizations_url":"https://api.github.com/users/mattklein123/orgs","repos_url":"https://api.github.com/users/mattklein123/repos","events_url":"https://api.github.com/users/mattklein123/events{/privacy}","received_events_url":"https://api.github.com/users/mattklein123/received_events","type":"User","site_admin":false},"body":"nit: this debug log doesn't add much value","created_at":"2017-06-23T15:54:00Z","updated_at":"2017-06-23T15:57:48Z","html_url":"https://github.com/lyft/envoy/pull/1079#discussion_r123783165","pull_request_url":"https://api.github.com/repos/lyft/envoy/pulls/1079","_links":{"self":{"href":"https://api.github.com/repos/lyft/envoy/pulls/comments/123783165"},"html":{"href":"https://github.com/lyft/envoy/pull/1079#discussion_r123783165"},"pull_request":{"href":"https://api.github.com/repos/lyft/envoy/pulls/1079"}}},"pull_request":{"url":"https://api.github.com/repos/lyft/envoy/pulls/1079","id":124940672,"html_url":"https://github.com/lyft/envoy/pull/1079","diff_url":"https://github.com/lyft/envoy/pull/1079.diff","patch_url":"https://github.com/lyft/envoy/pull/1079.patch","issue_url":"https://api.github.com/repos/lyft/envoy/issues/1079","number":1079,"state":"open","locked":false,"title":"Add a filter to support HTTP/JSON<->gRPC transcoding","user":{"login":"lizan","id":1016047,"avatar_url":"https://avatars2.githubusercontent.com/u/1016047?v=3","gravatar_id":"","url":"https://api.github.com/users/lizan","html_url":"https://github.com/lizan","followers_url":"https://api.github.com/users/lizan/followers","following_url":"https://api.github.com/users/lizan/following{/other_user}","gists_url":"https://api.github.com/users/lizan/gists{/gist_id}","starred_url":"https://api.github.com/users/lizan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lizan/subscriptions","organizations_url":"https://api.github.com/users/lizan/orgs","repos_url":"https://api.github.com/users/lizan/repos","events_url":"https://api.github.com/users/lizan/events{/privacy}","received_events_url":"https://api.github.com/users/lizan/received_events","type":"User","site_admin":false},"body":"This is still WIP, DO NOT MERGE.\r\nTo give contexts to small PRs.\r\n\r\nCloses #501","created_at":"2017-06-09T20:04:19Z","updated_at":"2017-06-23T15:57:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4e99de2b1625163eff9950387dc57587b7b1e25b","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/lyft/envoy/pulls/1079/commits","review_comments_url":"https://api.github.com/repos/lyft/envoy/pulls/1079/comments","review_comment_url":"https://api.github.com/repos/lyft/envoy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/lyft/envoy/issues/1079/comments","statuses_url":"https://api.github.com/repos/lyft/envoy/statuses/41416cdfffca73667685fa2ae0de1b391a797774","head":{"label":"lizan:grpc_json_transcoding","ref":"grpc_json_transcoding","sha":"41416cdfffca73667685fa2ae0de1b391a797774","user":{"login":"lizan","id":1016047,"avatar_url":"https://avatars2.githubusercontent.com/u/1016047?v=3","gravatar_id":"","url":"https://api.github.com/users/lizan","html_url":"https://github.com/lizan","followers_url":"https://api.github.com/users/lizan/followers","following_url":"https://api.github.com/users/lizan/following{/other_user}","gists_url":"https://api.github.com/users/lizan/gists{/gist_id}","starred_url":"https://api.github.com/users/lizan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lizan/subscriptions","organizations_url":"https://api.github.com/users/lizan/orgs","repos_url":"https://api.github.com/users/lizan/repos","events_url":"https://api.github.com/users/lizan/events{/privacy}","received_events_url":"https://api.github.com/users/lizan/received_events","type":"User","site_admin":false},"repo":{"id":76685528,"name":"envoy","full_name":"lizan/envoy","owner":{"login":"lizan","id":1016047,"avatar_url":"https://avatars2.githubusercontent.com/u/1016047?v=3","gravatar_id":"","url":"https://api.github.com/users/lizan","html_url":"https://github.com/lizan","followers_url":"https://api.github.com/users/lizan/followers","following_url":"https://api.github.com/users/lizan/following{/other_user}","gists_url":"https://api.github.com/users/lizan/gists{/gist_id}","starred_url":"https://api.github.com/users/lizan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lizan/subscriptions","organizations_url":"https://api.github.com/users/lizan/orgs","repos_url":"https://api.github.com/users/lizan/repos","events_url":"https://api.github.com/users/lizan/events{/privacy}","received_events_url":"https://api.github.com/users/lizan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lizan/envoy","description":"C++ front/service proxy","fork":true,"url":"https://api.github.com/repos/lizan/envoy","forks_url":"https://api.github.com/repos/lizan/envoy/forks","keys_url":"https://api.github.com/repos/lizan/envoy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lizan/envoy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lizan/envoy/teams","hooks_url":"https://api.github.com/repos/lizan/envoy/hooks","issue_events_url":"https://api.github.com/repos/lizan/envoy/issues/events{/number}","events_url":"https://api.github.com/repos/lizan/envoy/events","assignees_url":"https://api.github.com/repos/lizan/envoy/assignees{/user}","branches_url":"https://api.github.com/repos/lizan/envoy/branches{/branch}","tags_url":"https://api.github.com/repos/lizan/envoy/tags","blobs_url":"https://api.github.com/repos/lizan/envoy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lizan/envoy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lizan/envoy/git/refs{/sha}","trees_url":"https://api.github.com/repos/lizan/envoy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lizan/envoy/statuses/{sha}","languages_url":"https://api.github.com/repos/lizan/envoy/languages","stargazers_url":"https://api.github.com/repos/lizan/envoy/stargazers","contributors_url":"https://api.github.com/repos/lizan/envoy/contributors","subscribers_url":"https://api.github.com/repos/lizan/envoy/subscribers","subscription_url":"https://api.github.com/repos/lizan/envoy/subscription","commits_url":"https://api.github.com/repos/lizan/envoy/commits{/sha}","git_commits_url":"https://api.github.com/repos/lizan/envoy/git/commits{/sha}","comments_url":"https://api.github.com/repos/lizan/envoy/comments{/number}","issue_comment_url":"https://api.github.com/repos/lizan/envoy/issues/comments{/number}","contents_url":"https://api.github.com/repos/lizan/envoy/contents/{+path}","compare_url":"https://api.github.com/repos/lizan/envoy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lizan/envoy/merges","archive_url":"https://api.github.com/repos/lizan/envoy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lizan/envoy/downloads","issues_url":"https://api.github.com/repos/lizan/envoy/issues{/number}","pulls_url":"https://api.github.com/repos/lizan/envoy/pulls{/number}","milestones_url":"https://api.github.com/repos/lizan/envoy/milestones{/number}","notifications_url":"https://api.github.com/repos/lizan/envoy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lizan/envoy/labels{/name}","releases_url":"https://api.github.com/repos/lizan/envoy/releases{/id}","deployments_url":"https://api.github.com/repos/lizan/envoy/deployments","created_at":"2016-12-16T21:03:55Z","updated_at":"2016-12-16T21:03:57Z","pushed_at":"2017-06-23T00:40:18Z","git_url":"git://github.com/lizan/envoy.git","ssh_url":"git@github.com:lizan/envoy.git","clone_url":"https://github.com/lizan/envoy.git","svn_url":"https://github.com/lizan/envoy","homepage":"https://lyft.github.io/envoy","size":8056,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"lyft:master","ref":"master","sha":"30088c99d1112832a1ed2e69d12a6f5510c264ea","user":{"login":"lyft","id":4269340,"avatar_url":"https://avatars1.githubusercontent.com/u/4269340?v=3","gravatar_id":"","url":"https://api.github.com/users/lyft","html_url":"https://github.com/lyft","followers_url":"https://api.github.com/users/lyft/followers","following_url":"https://api.github.com/users/lyft/following{/other_user}","gists_url":"https://api.github.com/users/lyft/gists{/gist_id}","starred_url":"https://api.github.com/users/lyft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lyft/subscriptions","organizations_url":"https://api.github.com/users/lyft/orgs","repos_url":"https://api.github.com/users/lyft/repos","events_url":"https://api.github.com/users/lyft/events{/privacy}","received_events_url":"https://api.github.com/users/lyft/received_events","type":"Organization","site_admin":false},"repo":{"id":65214191,"name":"envoy","full_name":"lyft/envoy","owner":{"login":"lyft","id":4269340,"avatar_url":"https://avatars1.githubusercontent.com/u/4269340?v=3","gravatar_id":"","url":"https://api.github.com/users/lyft","html_url":"https://github.com/lyft","followers_url":"https://api.github.com/users/lyft/followers","following_url":"https://api.github.com/users/lyft/following{/other_user}","gists_url":"https://api.github.com/users/lyft/gists{/gist_id}","starred_url":"https://api.github.com/users/lyft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lyft/subscriptions","organizations_url":"https://api.github.com/users/lyft/orgs","repos_url":"https://api.github.com/users/lyft/repos","events_url":"https://api.github.com/users/lyft/events{/privacy}","received_events_url":"https://api.github.com/users/lyft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/lyft/envoy","description":"C++ front/service proxy","fork":false,"url":"https://api.github.com/repos/lyft/envoy","forks_url":"https://api.github.com/repos/lyft/envoy/forks","keys_url":"https://api.github.com/repos/lyft/envoy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lyft/envoy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lyft/envoy/teams","hooks_url":"https://api.github.com/repos/lyft/envoy/hooks","issue_events_url":"https://api.github.com/repos/lyft/envoy/issues/events{/number}","events_url":"https://api.github.com/repos/lyft/envoy/events","assignees_url":"https://api.github.com/repos/lyft/envoy/assignees{/user}","branches_url":"https://api.github.com/repos/lyft/envoy/branches{/branch}","tags_url":"https://api.github.com/repos/lyft/envoy/tags","blobs_url":"https://api.github.com/repos/lyft/envoy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lyft/envoy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lyft/envoy/git/refs{/sha}","trees_url":"https://api.github.com/repos/lyft/envoy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lyft/envoy/statuses/{sha}","languages_url":"https://api.github.com/repos/lyft/envoy/languages","stargazers_url":"https://api.github.com/repos/lyft/envoy/stargazers","contributors_url":"https://api.github.com/repos/lyft/envoy/contributors","subscribers_url":"https://api.github.com/repos/lyft/envoy/subscribers","subscription_url":"https://api.github.com/repos/lyft/envoy/subscription","commits_url":"https://api.github.com/repos/lyft/envoy/commits{/sha}","git_commits_url":"https://api.github.com/repos/lyft/envoy/git/commits{/sha}","comments_url":"https://api.github.com/repos/lyft/envoy/comments{/number}","issue_comment_url":"https://api.github.com/repos/lyft/envoy/issues/comments{/number}","contents_url":"https://api.github.com/repos/lyft/envoy/contents/{+path}","compare_url":"https://api.github.com/repos/lyft/envoy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lyft/envoy/merges","archive_url":"https://api.github.com/repos/lyft/envoy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lyft/envoy/downloads","issues_url":"https://api.github.com/repos/lyft/envoy/issues{/number}","pulls_url":"https://api.github.com/repos/lyft/envoy/pulls{/number}","milestones_url":"https://api.github.com/repos/lyft/envoy/milestones{/number}","notifications_url":"https://api.github.com/repos/lyft/envoy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lyft/envoy/labels{/name}","releases_url":"https://api.github.com/repos/lyft/envoy/releases{/id}","deployments_url":"https://api.github.com/repos/lyft/envoy/deployments","created_at":"2016-08-08T15:07:24Z","updated_at":"2017-06-23T15:04:48Z","pushed_at":"2017-06-23T15:38:34Z","git_url":"git://github.com/lyft/envoy.git","ssh_url":"git@github.com:lyft/envoy.git","clone_url":"https://github.com/lyft/envoy.git","svn_url":"https://github.com/lyft/envoy","homepage":"https://lyft.github.io/envoy","size":26902,"stargazers_count":1722,"watchers_count":1722,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":176,"mirror_url":null,"open_issues_count":115,"forks":176,"open_issues":115,"watchers":1722,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/lyft/envoy/pulls/1079"},"html":{"href":"https://github.com/lyft/envoy/pull/1079"},"issue":{"href":"https://api.github.com/repos/lyft/envoy/issues/1079"},"comments":{"href":"https://api.github.com/repos/lyft/envoy/issues/1079/comments"},"review_comments":{"href":"https://api.github.com/repos/lyft/envoy/pulls/1079/comments"},"review_comment":{"href":"https://api.github.com/repos/lyft/envoy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/lyft/envoy/pulls/1079/commits"},"statuses":{"href":"https://api.github.com/repos/lyft/envoy/statuses/41416cdfffca73667685fa2ae0de1b391a797774"}}}}
{"actor":{"display_login":"mattklein123"}}