2020#include < google/protobuf/text_format.h>
2121#include < gflags/gflags.h>
2222#include < string>
23+
2324#include " brpc/policy/http_rpc_protocol.h"
24- #include " butil/unique_ptr.h" // std::unique_ptr
25- #include " butil/string_splitter.h" // StringMultiSplitter
25+
2626#include " butil/string_printf.h"
27- #include " butil/time.h"
27+ #include " butil/string_splitter.h" // StringMultiSplitter
28+ #include " butil/strings/string_util.h"
2829#include " butil/sys_byteorder.h"
30+ #include " butil/time.h"
31+ #include " butil/unique_ptr.h" // std::unique_ptr
32+
2933#include " json2pb/pb_to_json.h" // ProtoMessageToJson
3034#include " json2pb/json_to_pb.h" // JsonToProtoMessage
3135#include " brpc/compress.h"
@@ -284,7 +288,7 @@ static bool JsonToProtoMessage(const butil::IOBuf& body,
284288 bool ok = json2pb::JsonToProtoMessage (&wrapper, message, options, &error);
285289 if (!ok) {
286290 cntl->SetFailed (error_code, " Fail to parse http json body as %s: %s" ,
287- message->GetDescriptor ()->full_name ().c_str (),
291+ butil::EnsureString ( message->GetDescriptor ()->full_name () ).c_str (),
288292 error.c_str ());
289293 }
290294 return ok;
@@ -305,7 +309,7 @@ static bool ProtoMessageToJson(const google::protobuf::Message& message,
305309 bool ok = json2pb::ProtoMessageToJson (message, wrapper, options, &error);
306310 if (!ok) {
307311 cntl->SetFailed (error_code, " Fail to convert %s to json: %s" ,
308- message.GetDescriptor ()->full_name ().c_str (),
312+ butil::EnsureString ( message.GetDescriptor ()->full_name () ).c_str (),
309313 error.c_str ());
310314 }
311315 return ok;
@@ -321,7 +325,7 @@ static bool ProtoJsonToProtoMessage(const butil::IOBuf& body,
321325 bool ok = json2pb::ProtoJsonToProtoMessage (&wrapper, message, options, &error);
322326 if (!ok) {
323327 cntl->SetFailed (error_code, " Fail to parse http proto-json body as %s: %s" ,
324- message->GetDescriptor ()->full_name ().c_str (),
328+ butil::EnsureString ( message->GetDescriptor ()->full_name () ).c_str (),
325329 error.c_str ());
326330 }
327331 return ok;
@@ -337,7 +341,7 @@ static bool ProtoMessageToProtoJson(const google::protobuf::Message& message,
337341 bool ok = json2pb::ProtoMessageToProtoJson (message, wrapper, options, &error);
338342 if (!ok) {
339343 cntl->SetFailed (error_code, " Fail to convert %s to proto-json: %s" ,
340- message.GetDescriptor ()->full_name ().c_str (), error.c_str ());
344+ butil::EnsureString ( message.GetDescriptor ()->full_name () ).c_str (), error.c_str ());
341345 }
342346 return ok;
343347}
@@ -527,13 +531,13 @@ void ProcessHttpResponse(InputMessageBase* msg) {
527531 if (content_type == HTTP_CONTENT_PROTO) {
528532 if (!ParsePbFromIOBuf (cntl->response (), res_body)) {
529533 cntl->SetFailed (ERESPONSE, " Fail to parse content as %s" ,
530- cntl->response ()->GetDescriptor ()->full_name ().c_str ());
534+ butil::EnsureString ( cntl->response ()->GetDescriptor ()->full_name () ).c_str ());
531535 break ;
532536 }
533537 } else if (content_type == HTTP_CONTENT_PROTO_TEXT) {
534538 if (!ParsePbTextFromIOBuf (cntl->response (), res_body)) {
535539 cntl->SetFailed (ERESPONSE, " Fail to parse proto-text content as %s" ,
536- cntl->response ()->GetDescriptor ()->full_name ().c_str ());
540+ butil::EnsureString ( cntl->response ()->GetDescriptor ()->full_name () ).c_str ());
537541 break ;
538542 }
539543 } else if (content_type == HTTP_CONTENT_JSON) {
@@ -612,13 +616,13 @@ void SerializeHttpRequest(butil::IOBuf* /*not used*/,
612616 if (!pbreq->SerializeToZeroCopyStream (&wrapper)) {
613617 cntl->request_attachment ().clear ();
614618 return cntl->SetFailed (EREQUEST, " Fail to serialize %s" ,
615- pbreq->GetTypeName ().c_str ());
619+ butil::EnsureString ( pbreq->GetTypeName () ).c_str ());
616620 }
617621 } else if (content_type == HTTP_CONTENT_PROTO_TEXT) {
618622 if (!google::protobuf::TextFormat::Print (*pbreq, &wrapper)) {
619623 cntl->request_attachment ().clear ();
620624 return cntl->SetFailed (EREQUEST, " Fail to print %s as proto-text" ,
621- pbreq->GetTypeName ().c_str ());
625+ butil::EnsureString ( pbreq->GetTypeName () ).c_str ());
622626 }
623627 } else if (content_type == HTTP_CONTENT_PROTO_JSON) {
624628 if (!ProtoMessageToProtoJson (*pbreq, &wrapper, cntl, EREQUEST)) {
@@ -880,11 +884,13 @@ HttpResponseSender::~HttpResponseSender() {
880884 butil::IOBufAsZeroCopyOutputStream wrapper (&cntl->response_attachment ());
881885 if (content_type == HTTP_CONTENT_PROTO) {
882886 if (!res->SerializeToZeroCopyStream (&wrapper)) {
883- cntl->SetFailed (ERESPONSE, " Fail to serialize %s" , res->GetTypeName ().c_str ());
887+ cntl->SetFailed (ERESPONSE, " Fail to serialize %s" ,
888+ butil::EnsureString (res->GetTypeName ()).c_str ());
884889 }
885890 } else if (content_type == HTTP_CONTENT_PROTO_TEXT) {
886891 if (!google::protobuf::TextFormat::Print (*res, &wrapper)) {
887- cntl->SetFailed (ERESPONSE, " Fail to print %s as proto-text" , res->GetTypeName ().c_str ());
892+ cntl->SetFailed (ERESPONSE, " Fail to print %s as proto-text" ,
893+ butil::EnsureString (res->GetTypeName ()).c_str ());
888894 }
889895 } else if (content_type == HTTP_CONTENT_PROTO_JSON) {
890896 ProtoMessageToProtoJson (*res, &wrapper, cntl, ERESPONSE);
@@ -1535,7 +1541,7 @@ void ProcessHttpRequest(InputMessageBase *msg) {
15351541 cntl->request_attachment ().swap (req_body);
15361542 google::protobuf::Closure* done = new HttpResponseSenderAsDone (&resp_sender);
15371543 if (span) {
1538- span->ResetServerSpanName (md->full_name ());
1544+ span->ResetServerSpanName (butil::EnsureString ( md->full_name () ));
15391545 span->set_start_callback_us (butil::cpuwide_time_us ());
15401546 span->AsParent ();
15411547 }
@@ -1565,18 +1571,19 @@ void ProcessHttpRequest(InputMessageBase *msg) {
15651571 // Switch to service-specific error.
15661572 non_service_error.release ();
15671573 MethodStatus* method_status = mp->status ;
1574+ const std::string method_full_name = butil::EnsureString (mp->method ->full_name ());
15681575 resp_sender.set_method_status (method_status);
15691576 if (method_status) {
15701577 int rejected_cc = 0 ;
15711578 if (!method_status->OnRequested (&rejected_cc)) {
15721579 cntl->SetFailed (ELIMIT, " Rejected by %s's ConcurrencyLimiter, concurrency=%d" ,
1573- mp-> method -> full_name () .c_str (), rejected_cc);
1580+ method_full_name .c_str (), rejected_cc);
15741581 return ;
15751582 }
15761583 }
15771584
15781585 if (span) {
1579- span->ResetServerSpanName (mp-> method -> full_name () );
1586+ span->ResetServerSpanName (method_full_name );
15801587 }
15811588 // NOTE: accesses to builtin services are not counted as part of
15821589 // concurrency, therefore are not limited by ServerOptions.max_concurrency.
@@ -1616,6 +1623,8 @@ void ProcessHttpRequest(InputMessageBase *msg) {
16161623 google::protobuf::Message* req = messages->Request ();
16171624 google::protobuf::Message* res = messages->Response ();
16181625
1626+ const std::string request_full_name = butil::EnsureString (req->GetDescriptor ()->full_name ());
1627+
16191628 if (__builtin_expect (!req || !res, 0 )) {
16201629 PLOG (FATAL) << " Fail to new req or res" ;
16211630 cntl->SetFailed (" Fail to new req or res" );
@@ -1632,7 +1641,7 @@ void ProcessHttpRequest(InputMessageBase *msg) {
16321641 if (!req->IsInitialized ()) {
16331642 cntl->SetFailed (EREQUEST, " %s needs to be created from a"
16341643 " non-empty json, it has required fields." ,
1635- req-> GetDescriptor ()-> full_name () .c_str ());
1644+ request_full_name .c_str ());
16361645 return ;
16371646 } // else all fields of the request are optional.
16381647 } else {
@@ -1677,13 +1686,13 @@ void ProcessHttpRequest(InputMessageBase *msg) {
16771686 if (content_type == HTTP_CONTENT_PROTO) {
16781687 if (!ParsePbFromIOBuf (req, req_body)) {
16791688 cntl->SetFailed (EREQUEST, " Fail to parse http body as %s" ,
1680- req-> GetDescriptor ()-> full_name () .c_str ());
1689+ request_full_name .c_str ());
16811690 return ;
16821691 }
16831692 } else if (content_type == HTTP_CONTENT_PROTO_TEXT) {
16841693 if (!ParsePbTextFromIOBuf (req, req_body)) {
16851694 cntl->SetFailed (EREQUEST, " Fail to parse http proto-text body as %s" ,
1686- req-> GetDescriptor ()-> full_name () .c_str ());
1695+ request_full_name .c_str ());
16871696 return ;
16881697 }
16891698 } else if (content_type == HTTP_CONTENT_PROTO_JSON) {
0 commit comments