Skip to content

Commit e904c33

Browse files
committed
Avoid multiple reallocations when receive a big buffer in post method call.
1 parent 89c932f commit e904c33

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

httplib.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,11 @@ using ssize_t = __int64;
209209
#endif // _MSC_VER
210210

211211
#ifndef S_ISREG
212-
#define S_ISREG(m) (((m) & S_IFREG) == S_IFREG)
212+
#define S_ISREG(m) (((m)&S_IFREG) == S_IFREG)
213213
#endif // S_ISREG
214214

215215
#ifndef S_ISDIR
216-
#define S_ISDIR(m) (((m) & S_IFDIR) == S_IFDIR)
216+
#define S_ISDIR(m) (((m)&S_IFDIR) == S_IFDIR)
217217
#endif // S_ISDIR
218218

219219
#ifndef NOMINMAX
@@ -7819,8 +7819,11 @@ inline bool Server::read_content_core(
78197819
multipart_receiver);
78207820
};
78217821
} else {
7822-
out = [receiver](const char *buf, size_t n, size_t /*off*/,
7823-
size_t /*len*/) { return receiver(buf, n); };
7822+
out = [receiver, &req](const char *buf, size_t n, size_t /*off*/,
7823+
size_t len) {
7824+
if (len > req.body.size()) { req.body.resize(len); }
7825+
return receiver(buf, n);
7826+
};
78247827
}
78257828

78267829
if (req.method == "DELETE" && !req.has_header("Content-Length")) {
@@ -11809,8 +11812,8 @@ inline void Client::set_follow_location(bool on) {
1180911812

1181011813
inline void Client::set_path_encode(bool on) { cli_->set_path_encode(on); }
1181111814

11812-
[[deprecated("Use set_path_encode instead")]]
11813-
inline void Client::set_url_encode(bool on) {
11815+
[[deprecated("Use set_path_encode instead")]] inline void
11816+
Client::set_url_encode(bool on) {
1181411817
cli_->set_path_encode(on);
1181511818
}
1181611819

0 commit comments

Comments
 (0)