Skip to content
This repository was archived by the owner on Aug 19, 2019. It is now read-only.

Commit 01277e5

Browse files
committed
Minor fixes to the batch code.
1 parent 20a6681 commit 01277e5

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

src/reporter.cc

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace http = boost::network::http;
3131
namespace google {
3232

3333
constexpr const char kMultipartBoundary[] = "publishMultipartPost";
34-
constexpr const char kBatchEndpoint[] = "/batch/resourceMetadatadata";
34+
constexpr const char kBatchEndpoint[] = "/batch/resourceMetadata";
3535
constexpr const char kMetadataIngestionPublishEndpoint[] =
3636
"/v1beta3/projects/{{project_id}}/resourceMetadata:publish";
3737

@@ -90,7 +90,7 @@ void SendMetadataRequest(std::vector<json::value>&& entries,
9090
bool use_batch)
9191
throw (boost::system::system_error) {
9292

93-
if (use_batch) {
93+
if (use_batch and (entries.size() > 1)) {
9494
const std::string batch_uri = host + kBatchEndpoint;
9595
const std::string content_type =
9696
std::string("multipart/mixed; boundary=") + kMultipartBoundary;
@@ -99,12 +99,14 @@ void SendMetadataRequest(std::vector<json::value>&& entries,
9999
request << boost::network::header("User-Agent", user_agent);
100100
request << boost::network::header("Content-Type", content_type);
101101
request << boost::network::header("Authorization", auth_header);
102+
request << boost::network::header("Expect", "100-continue");
102103
std::ostringstream out;
103-
out << std::endl << "--" << kMultipartBoundary << std::endl;
104+
out << std::endl;
104105

105106
for (json::value& entry : entries) {
106107
const json::Object* single_request = entry->As<json::Object>();
107108
std::string request_body = single_request->ToString();
109+
out << "--" << kMultipartBoundary << std::endl;
108110
out << "Content-Type: application/http" << std::endl;
109111
out << "Content-Transfer-Encoding: binary" << std::endl;
110112
out << "Content-ID: " << single_request->Get<json::String>("name")
@@ -115,20 +117,26 @@ void SendMetadataRequest(std::vector<json::value>&& entries,
115117
out << "Content-Length: " << std::to_string(request_body.size())
116118
<< std::endl;
117119
out << std::endl << request_body << std::endl;
118-
out << "--" << kMultipartBoundary << std::endl;
119120
}
121+
out << "--" << kMultipartBoundary << "--" << std::endl;
120122
std::string multipart_body = out.str();
121123
const int total_length = multipart_body.size();
122-
request << boost::network::header(
123-
"Content-Length", std::to_string(total_length));
124+
125+
request << boost::network::header("Content-Length",
126+
std::to_string(total_length));
124127
request << boost::network::body(multipart_body);
125128

126129
if (verbose_logging) {
127-
LOG(INFO) << "About to send request: POST " << batch_uri
128-
<< " User-Agent: " << user_agent
129-
<< " Content-Type: " << content_type
130-
<< " Context-Length: " << total_length
131-
<< std::endl << body(request);
130+
LOG(INFO) << "About to send request: POST " << batch_uri;
131+
LOG(INFO) << "Headers:";
132+
http::client::request::headers_container_type head = (headers(request));
133+
for (auto it = head.begin(); it != head.end(); ++it) {
134+
if (it->first == "Authorization") {
135+
continue;
136+
}
137+
LOG(INFO) << it->first << ": " << it->second;
138+
}
139+
LOG(INFO) << "Body:" << std::endl << body(request);
132140
}
133141

134142
http::client::response response = client.post(request);
@@ -148,7 +156,7 @@ void SendMetadataRequest(std::vector<json::value>&& entries,
148156
LOG(INFO) << "Headers:";
149157
http::client::response::headers_container_type head = (headers(response));
150158
for (auto it = head.begin(); it != head.end(); ++it) {
151-
LOG(INFO) << it->first << ":" << it->second;
159+
LOG(INFO) << it->first << ": " << it->second;
152160
}
153161
LOG(INFO) << "Body:" << std::endl << body(response);
154162
}

0 commit comments

Comments
 (0)