Skip to content

Commit

Permalink
Dump http header (#4)
Browse files Browse the repository at this point in the history
* dump header
  • Loading branch information
guodongxiaren authored Aug 22, 2021
1 parent 7d9621b commit 3b95a40
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/brpc/policy/http_rpc_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1486,12 +1486,14 @@ void ProcessHttpRequest(InputMessageBase *msg) {
}
SampledRequest* sample = AskToBeSampled();
if (sample) {
sample->meta.set_service_name(svc->GetDescriptor()->name());
sample->meta.set_method_name(method->name());
sample->meta.set_compress_type(COMPRESS_TYPE_NONE);
sample->meta.set_protocol_type(PROTOCOL_HTTP);
sample->meta.set_attachment_size(req_body.size());
sample->request = req_body;

butil::IOBuf sample_request;
butil::EndPoint ep;
MakeRawHttpRequest(&sample_request, &req_header, ep, &req_body);
sample->request = sample_request;
sample->submit(start_parse_us);
}
} else {
Expand Down
16 changes: 8 additions & 8 deletions tools/rpc_replay/rpc_replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <brpc/server.h>
#include <brpc/rpc_dump.h>
#include <brpc/serialized_request.h>
#include <brpc/details/http_message.h>
#include "info_thread.h"

DEFINE_string(dir, "", "The directory of dumped requests");
Expand Down Expand Up @@ -162,14 +163,13 @@ static void* replay_thread(void* arg) {
brpc::SerializedRequest* req_ptr = &req;
cntl->reset_sampled_request(sample_guard.release());
if (sample->meta.protocol_type() == brpc::PROTOCOL_HTTP) {
std::stringstream uri_ss;
uri_ss << "/" << sample->meta.service_name()
<< "/" << sample->meta.method_name();

cntl->http_request().uri() = uri_ss.str();
cntl->http_request().set_method(brpc::HTTP_METHOD_POST);
cntl->http_request().set_content_type("application/json");
cntl->request_attachment() = sample->request.movable();
brpc::HttpMessage http_message;
http_message.ParseFromIOBuf(sample->request);
cntl->http_request().Swap(http_message.header());
// clear origin Host in header
cntl->http_request().RemoveHeader("Host");
cntl->http_request().uri().set_host("");
cntl->request_attachment() = http_message.body().movable();

req_ptr = NULL;
} else if (sample->meta.attachment_size() > 0) {
Expand Down

0 comments on commit 3b95a40

Please sign in to comment.