Skip to content

Commit 956faae

Browse files
committed
Changed output type of read_content_??? functions to be std::string&
1 parent b6df220 commit 956faae

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

httplib.h

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -767,13 +767,12 @@ inline bool read_headers(Stream& strm, Headers& headers)
767767
return true;
768768
}
769769

770-
template <typename T>
771-
bool read_content_with_length(Stream& strm, T& x, size_t len, Progress progress)
770+
bool read_content_with_length(Stream& strm, std::string& out, size_t len, Progress progress)
772771
{
773-
x.body.assign(len, 0);
772+
out.assign(len, 0);
774773
size_t r = 0;
775774
while (r < len){
776-
auto n = strm.read(&x.body[r], len - r);
775+
auto n = strm.read(&out[r], len - r);
777776
if (n <= 0) {
778777
return false;
779778
}
@@ -788,8 +787,7 @@ bool read_content_with_length(Stream& strm, T& x, size_t len, Progress progress)
788787
return true;
789788
}
790789

791-
template <typename T>
792-
bool read_content_without_length(Stream& strm, T& x)
790+
bool read_content_without_length(Stream& strm, std::string& out)
793791
{
794792
for (;;) {
795793
char byte;
@@ -799,14 +797,13 @@ bool read_content_without_length(Stream& strm, T& x)
799797
} else if (n == 0) {
800798
return true;
801799
}
802-
x.body += byte;
800+
out += byte;
803801
}
804802

805803
return true;
806804
}
807805

808-
template <typename T>
809-
bool read_content_chunked(Stream& strm, T& x)
806+
bool read_content_chunked(Stream& strm, std::string& out)
810807
{
811808
const auto bufsiz = 16;
812809
char buf[bufsiz];
@@ -835,7 +832,7 @@ bool read_content_chunked(Stream& strm, T& x)
835832
break;
836833
}
837834

838-
x.body += chunk;
835+
out += chunk;
839836

840837
if (!reader.getline()) {
841838
return false;
@@ -859,14 +856,14 @@ bool read_content(Stream& strm, T& x, Progress progress = Progress())
859856
auto len = get_header_value_int(x.headers, "Content-Length", 0);
860857

861858
if (len) {
862-
return read_content_with_length(strm, x, len, progress);
859+
return read_content_with_length(strm, x.body, len, progress);
863860
} else {
864861
const auto& encoding = get_header_value(x.headers, "Transfer-Encoding", "");
865862

866863
if (!strcasecmp(encoding, "chunked")) {
867-
return read_content_chunked(strm, x);
864+
return read_content_chunked(strm, x.body);
868865
} else {
869-
return read_content_without_length(strm, x);
866+
return read_content_without_length(strm, x.body);
870867
}
871868
}
872869

0 commit comments

Comments
 (0)