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

Function handle_response

tools/rpc_view/rpc_view.cpp:30–64  ·  view source on GitHub ↗

handle HTTP response of accessing builtin services of the target server.

Source from the content-addressed store, hash-verified

28
29// handle HTTP response of accessing builtin services of the target server.
30static void handle_response(brpc::Controller* client_cntl,
31 std::string target,
32 brpc::Controller* server_cntl,
33 google::protobuf::Closure* server_done) {
34 // Copy all headers. The "Content-Length" will be overwriteen.
35 server_cntl->http_response() = client_cntl->http_response();
36 // Copy content.
37 server_cntl->response_attachment() = client_cntl->response_attachment();
38 // Insert "rpc_view: <target>" before </body> so that users are always
39 // visually notified with target server w/o confusions.
40 butil::IOBuf& content = server_cntl->response_attachment();
41 butil::IOBuf before_body;
42 if (content.cut_until(&before_body, "</body>") == 0) {
43 before_body.append(
44 "<style type=\"text/css\">\n"
45 ".rpcviewlogo {position: fixed; bottom: 0px; right: 0px;"
46 " color: #ffffff; background-color: #000000; }\n"
47 " </style>\n"
48 "<span class='rpcviewlogo'>&nbsp;rpc_view: ");
49 before_body.append(target);
50 before_body.append("&nbsp;</span></body>");
51 before_body.append(content);
52 content = before_body;
53 }
54 // Notice that we don't set RPC to failed on http errors because we
55 // want to pass unchanged content to the users otherwise RPC replaces
56 // the content with ErrorText.
57 if (client_cntl->Failed() &&
58 client_cntl->ErrorCode() != brpc::EHTTP) {
59 server_cntl->SetFailed(client_cntl->ErrorCode(),
60 "%s", client_cntl->ErrorText().c_str());
61 }
62 delete client_cntl;
63 server_done->Run();
64}
65
66// A http_master_service.
67class ViewServiceImpl : public ViewService {

Callers

nothing calls this directly

Calls 8

cut_untilMethod · 0.80
ErrorCodeMethod · 0.80
ErrorTextMethod · 0.80
appendMethod · 0.45
FailedMethod · 0.45
SetFailedMethod · 0.45
c_strMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected