MCPcopy Create free account
hub / github.com/apache/brpc / default_method

Method default_method

tools/rpc_view/rpc_view.cpp:71–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69 ViewServiceImpl() {}
70 virtual ~ViewServiceImpl() {}
71 virtual void default_method(google::protobuf::RpcController* cntl_base,
72 const HttpRequest*,
73 HttpResponse*,
74 google::protobuf::Closure* done) {
75 brpc::ClosureGuard done_guard(done);
76 brpc::Controller* server_cntl =
77 static_cast<brpc::Controller*>(cntl_base);
78
79 // Get or set target. Notice that we don't access FLAGS_target directly
80 // which is thread-unsafe (for string flags).
81 std::string target;
82 const std::string* newtarget =
83 server_cntl->http_request().uri().GetQuery("changetarget");
84 if (newtarget) {
85 if (GFLAGS_NAMESPACE::SetCommandLineOption("target", newtarget->c_str()).empty()) {
86 server_cntl->SetFailed("Fail to change value of -target");
87 return;
88 }
89 target = *newtarget;
90 } else {
91 if (!GFLAGS_NAMESPACE::GetCommandLineOption("target", &target)) {
92 server_cntl->SetFailed("Fail to get value of -target");
93 return;
94 }
95 }
96
97 // Create the http channel on-the-fly. Notice that we've set
98 // `defer_close_second' in main() so that dtor of channels do not
99 // close connections immediately and ad-hoc creation of channels
100 // often reuses the not-yet-closed connections.
101 brpc::Channel http_chan;
102 brpc::ChannelOptions http_chan_opt;
103 http_chan_opt.protocol = brpc::PROTOCOL_HTTP;
104 if (http_chan.Init(target.c_str(), &http_chan_opt) != 0) {
105 server_cntl->SetFailed(brpc::EINTERNAL,
106 "Fail to connect to %s", target.c_str());
107 return;
108 }
109
110 // Remove "Accept-Encoding". We need to insert additional texts
111 // before </body>, preventing the server from compressing the content
112 // simplifies our code. The additional bandwidth consumption shouldn't
113 // be an issue for infrequent checking out of builtin services pages.
114 server_cntl->http_request().RemoveHeader("Accept-Encoding");
115
116 brpc::Controller* client_cntl = new brpc::Controller;
117 client_cntl->http_request() = server_cntl->http_request();
118 // Remove "Host" so that RPC will laterly serialize the (correct)
119 // target server in.
120 client_cntl->http_request().RemoveHeader("host");
121
122 // Setup the URI.
123 const brpc::URI& server_uri = server_cntl->http_request().uri();
124 std::string uri = server_uri.path();
125 if (!server_uri.query().empty()) {
126 uri.push_back('?');
127 uri.append(server_uri.query());
128 }

Callers

nothing calls this directly

Calls 12

NewCallbackFunction · 0.85
GetQueryMethod · 0.80
set_timeout_msMethod · 0.80
emptyMethod · 0.45
c_strMethod · 0.45
SetFailedMethod · 0.45
InitMethod · 0.45
RemoveHeaderMethod · 0.45
push_backMethod · 0.45
appendMethod · 0.45
CallMethodMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected