@@ -66,8 +66,8 @@ CHttpResponse CClient::doRequest(const std::string &path,
66
66
client->set_header_container (&resHeaders);
67
67
}
68
68
69
- client->append_header (" Host" , host);
70
- client->append_header (" User-Agent" , " xt/1.0.1" );
69
+ // client->append_header("Host", host);
70
+ // client->append_header("User-Agent", "xt/1.0.1");
71
71
72
72
// logd("--------------header--------------");
73
73
for (auto &a : headers) {
@@ -121,8 +121,9 @@ CHttpResponse CClient::doRequest(const std::string &path,
121
121
122
122
if (ret != 200 ) {
123
123
logw (" connect to server failed. http response code: {}" , ret);
124
- return CHttpResponse{
125
- 500 , fmt::format (" 请求失败 status={} body={}" , ret, writer.string )};
124
+ return CHttpResponse{500 ,
125
+ fmt::format (" Request failed status={} body={}" ,
126
+ ret, writer.string )};
126
127
}
127
128
128
129
return CHttpResponse{static_cast <uint64_t >(ret), writer.string };
@@ -188,8 +189,9 @@ CClient::doRequestTest(const std::string &path, photon::net::http::Verb verb,
188
189
189
190
if (ret != 200 ) {
190
191
logw (" connect to server failed. http response code: {}" , ret);
191
- return CHttpResponse{
192
- 500 , fmt::format (" 请求失败 status={} body={}" , ret, writer.string )};
192
+ return CHttpResponse{500 ,
193
+ fmt::format (" Request failed status={} body={}" ,
194
+ ret, writer.string )};
193
195
}
194
196
195
197
return CHttpResponse{static_cast <uint64_t >(ret), writer.string };
@@ -209,7 +211,7 @@ SEQ_FUNC void seq_cclient_free(CClient *client) {
209
211
SEQ_FUNC int64_t seq_cclient_do_request (
210
212
CClient *client, const char *path, size_t path_len, int64_t verb,
211
213
std::map<std::string, std::string> *headers, const char *body,
212
- size_t body_len, char *res, size_t *n, bool verbose) {
214
+ size_t body_len, char *res, size_t res_len, size_t *n, bool verbose) {
213
215
// logd("seq_cclient_do_request");
214
216
std::string reqeustPath = std::string (path, path_len);
215
217
std::string body_ (body, body_len);
@@ -228,7 +230,14 @@ SEQ_FUNC int64_t seq_cclient_do_request(
228
230
auto result = client->doRequest (reqeustPath, v, *headers, body_, verbose);
229
231
// logd("seq_cclient_do_request success");
230
232
auto &res_body = result.body ;
231
- memcpy (res, res_body.c_str (), res_body.length ());
232
- *n = res_body.length ();
233
+ if (res_body.length () < res_len) {
234
+ memcpy (res, res_body.c_str (), res_body.length ());
235
+ *n = res_body.length ();
236
+ } else {
237
+ memcpy (res, res_body.c_str (), res_len);
238
+ *n = res_len;
239
+ logw (" response body is too long. baseUrl={}, path={}" ,
240
+ client->getBaseUrl (), reqeustPath);
241
+ }
233
242
return result.status_code ;
234
243
}
0 commit comments