Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions httplib.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ using socket_t = int;
#include <errno.h>
#include <exception>
#include <fcntl.h>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
Expand Down Expand Up @@ -2387,8 +2386,6 @@ std::string encode_query_param(const std::string &value);

std::string decode_url(const std::string &s, bool convert_plus_to_space);

void read_file(const std::string &path, std::string &out);

std::string trim_copy(const std::string &s);

void divide(
Expand Down Expand Up @@ -2916,15 +2913,6 @@ inline std::string decode_url(const std::string &s,
return result;
}

inline void read_file(const std::string &path, std::string &out) {
std::ifstream fs(path, std::ios_base::binary);
fs.seekg(0, std::ios_base::end);
auto size = fs.tellg();
fs.seekg(0);
out.resize(static_cast<size_t>(size));
fs.read(&out[0], static_cast<std::streamsize>(size));
}

inline std::string file_extension(const std::string &path) {
std::smatch m;
static auto re = std::regex("\\.([a-zA-Z0-9]+)$");
Expand Down
19 changes: 15 additions & 4 deletions test/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <atomic>
#include <chrono>
#include <fstream>
#include <future>
#include <limits>
#include <memory>
Expand Down Expand Up @@ -59,6 +60,16 @@ MultipartFormData &get_file_value(MultipartFormDataItems &files,
#endif
}

static void read_file(const std::string &path, std::string &out) {
std::ifstream fs(path, std::ios_base::binary);
if (!fs) throw std::runtime_error("File not found: " + path);
fs.seekg(0, std::ios_base::end);
auto size = fs.tellg();
fs.seekg(0);
out.resize(static_cast<size_t>(size));
fs.read(&out[0], static_cast<std::streamsize>(size));
}

#ifndef _WIN32
class UnixSocketTest : public ::testing::Test {
protected:
Expand Down Expand Up @@ -729,7 +740,7 @@ TEST(ChunkedEncodingTest, FromHTTPWatch_Online) {
ASSERT_TRUE(res);

std::string out;
detail::read_file("./image.jpg", out);
read_file("./image.jpg", out);

EXPECT_EQ(StatusCode::OK_200, res->status);
EXPECT_EQ(out, res->body);
Expand Down Expand Up @@ -782,7 +793,7 @@ TEST(ChunkedEncodingTest, WithContentReceiver_Online) {
ASSERT_TRUE(res);

std::string out;
detail::read_file("./image.jpg", out);
read_file("./image.jpg", out);

EXPECT_EQ(StatusCode::OK_200, res->status);
EXPECT_EQ(out, body);
Expand Down Expand Up @@ -814,7 +825,7 @@ TEST(ChunkedEncodingTest, WithResponseHandlerAndContentReceiver_Online) {
ASSERT_TRUE(res);

std::string out;
detail::read_file("./image.jpg", out);
read_file("./image.jpg", out);

EXPECT_EQ(StatusCode::OK_200, res->status);
EXPECT_EQ(out, body);
Expand Down Expand Up @@ -6164,7 +6175,7 @@ TEST(SSLClientTest, ServerCertificateVerification4) {

TEST(SSLClientTest, ServerCertificateVerification5_Online) {
std::string cert;
detail::read_file(CA_CERT_FILE, cert);
read_file(CA_CERT_FILE, cert);

SSLClient cli("google.com");
cli.load_ca_cert_store(cert.data(), cert.size());
Expand Down
Loading