mirror of
https://github.com/yhirose/cpp-httplib
synced 2026-06-08 18:30:49 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 89740a808d | |||
| 2377a20e0b | |||
| 5e43680486 | |||
| 79df842cc5 | |||
| 48a4a5812e | |||
| a7a6df49a4 | |||
| e932c7e1ec |
@@ -349,8 +349,6 @@ std::shared_ptr<httplib::Response> res =
|
||||
|
||||

|
||||
|
||||
This feature was contributed by [underscorediscovery](https://github.com/yhirose/cpp-httplib/pull/23).
|
||||
|
||||
### Authentication
|
||||
|
||||
```cpp
|
||||
@@ -490,4 +488,47 @@ g++ 4.8 and below cannot build this library since `<regex>` in the versions are
|
||||
License
|
||||
-------
|
||||
|
||||
MIT license (© 2019 Yuji Hirose)
|
||||
MIT license (© 2020 Yuji Hirose)
|
||||
|
||||
Special Thanks To
|
||||
-----------------
|
||||
|
||||
The following folks made great contributions to polish this library to totally another level from a simple toy!
|
||||
|
||||
* [Zefz](https://github.com/Zefz)
|
||||
* [PixlRainbow](https://github.com/PixlRainbow)
|
||||
* [sgraham](https://github.com/sgraham)
|
||||
* [mrexodia](https://github.com/mrexodia)
|
||||
* [hyperxor](https://github.com/hyperxor)
|
||||
* [omaralvarez](https://github.com/omaralvarez)
|
||||
* [vvanelslande](https://github.com/vvanelslande)
|
||||
* [underscorediscovery](https://github.com/underscorediscovery)
|
||||
* [sux2mfgj](https://github.com/sux2mfgj)
|
||||
* [matvore](https://github.com/matvore)
|
||||
* [intmain-io](https://github.com/intmain)
|
||||
* [davidgfnet](https://github.com/davidgfnet)
|
||||
* [crtxcr](https://github.com/crtxcr)
|
||||
* [const-volatile](https://github.com/const)
|
||||
* [aguadoenzo](https://github.com/aguadoenzo)
|
||||
* [TheMaverickProgrammer](https://github.com/TheMaverickProgrammer)
|
||||
* [vdudouyt](https://github.com/vdudouyt)
|
||||
* [stupedama](https://github.com/stupedama)
|
||||
* [rockwotj](https://github.com/rockwotj)
|
||||
* [marknelson](https://github.com/marknelson)
|
||||
* [jaspervandeven](https://github.com/jaspervandeven)
|
||||
* [hans-erickson](https://github.com/hans)
|
||||
* [ha11owed](https://github.com/ha11owed)
|
||||
* [gulrak](https://github.com/gulrak)
|
||||
* [dolphineye](https://github.com/dolphineye)
|
||||
* [danielzehe](https://github.com/danielzehe)
|
||||
* [batist73](https://github.com/batist73)
|
||||
* [barryam3](https://github.com/barryam3)
|
||||
* [adikabintang](https://github.com/adikabintang)
|
||||
* [aaronalbers](https://github.com/aaronalbers)
|
||||
* [Whitetigerswt](https://github.com/Whitetigerswt)
|
||||
* [TangHuaiZhe](https://github.com/TangHuaiZhe)
|
||||
* [Sil3ntStorm](https://github.com/Sil3ntStorm)
|
||||
* [MannyClicks](https://github.com/MannyClicks)
|
||||
* [DraTeots](https://github.com/DraTeots)
|
||||
* [BastienDurel](https://github.com/BastienDurel)
|
||||
* [vitalyster](https://github.com/vitalyster)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// httplib.h
|
||||
//
|
||||
// Copyright (c) 2019 Yuji Hirose. All rights reserved.
|
||||
// Copyright (c) 2020 Yuji Hirose. All rights reserved.
|
||||
// MIT License
|
||||
//
|
||||
|
||||
@@ -509,7 +509,7 @@ private:
|
||||
bool listen_internal();
|
||||
|
||||
bool routing(Request &req, Response &res, Stream &strm, bool last_connection);
|
||||
bool handle_file_request(Request &req, Response &res);
|
||||
bool handle_file_request(Request &req, Response &res, bool head = false);
|
||||
bool dispatch_request(Request &req, Response &res, Handlers &handlers);
|
||||
bool dispatch_request_for_content_reader(Request &req, Response &res,
|
||||
ContentReader content_reader,
|
||||
@@ -3212,7 +3212,7 @@ inline bool Server::read_content_core(Stream &strm, bool last_connection,
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Server::handle_file_request(Request &req, Response &res) {
|
||||
inline bool Server::handle_file_request(Request &req, Response &res, bool head) {
|
||||
for (const auto &kv : base_dirs_) {
|
||||
const auto &mount_point = kv.first;
|
||||
const auto &base_dir = kv.second;
|
||||
@@ -3230,7 +3230,7 @@ inline bool Server::handle_file_request(Request &req, Response &res) {
|
||||
detail::find_content_type(path, file_extension_and_mimetype_map_);
|
||||
if (type) { res.set_header("Content-Type", type); }
|
||||
res.status = 200;
|
||||
if (file_request_handler_) { file_request_handler_(req, res); }
|
||||
if (!head && file_request_handler_) { file_request_handler_(req, res); }
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -3331,7 +3331,8 @@ inline bool Server::listen_internal() {
|
||||
inline bool Server::routing(Request &req, Response &res, Stream &strm,
|
||||
bool last_connection) {
|
||||
// File handler
|
||||
if (req.method == "GET" && handle_file_request(req, res)) { return true; }
|
||||
bool is_head_request = req.method == "HEAD";
|
||||
if ((req.method == "GET" || is_head_request) && handle_file_request(req, res, is_head_request)) { return true; }
|
||||
|
||||
if (detail::expect_content(req)) {
|
||||
// Content reader handler
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
border = '// ----------------------------------------------------------------------------'
|
||||
|
||||
PythonVersion = sys.version_info[0];
|
||||
|
||||
with open('httplib.h') as f:
|
||||
lines = f.readlines()
|
||||
inImplementation = False
|
||||
os.makedirs('out', exist_ok=True)
|
||||
|
||||
if PythonVersion < 3:
|
||||
os.makedirs('out')
|
||||
else:
|
||||
os.makedirs('out', exist_ok=True)
|
||||
|
||||
with open('out/httplib.h', 'w') as fh:
|
||||
with open('out/httplib.cc', 'w') as fc:
|
||||
fc.write('#include "httplib.h"\n')
|
||||
|
||||
@@ -1051,6 +1051,15 @@ TEST_F(ServerTest, HeadMethod200) {
|
||||
EXPECT_EQ("", res->body);
|
||||
}
|
||||
|
||||
TEST_F(ServerTest, HeadMethod200Static) {
|
||||
auto res = cli_.Head("/mount/dir/index.html");
|
||||
ASSERT_TRUE(res != nullptr);
|
||||
EXPECT_EQ(200, res->status);
|
||||
EXPECT_EQ("text/html", res->get_header_value("Content-Type"));
|
||||
EXPECT_EQ(104, std::stoi(res->get_header_value("Content-Length")));
|
||||
EXPECT_EQ("", res->body);
|
||||
}
|
||||
|
||||
TEST_F(ServerTest, HeadMethod404) {
|
||||
auto res = cli_.Head("/invalid");
|
||||
ASSERT_TRUE(res != nullptr);
|
||||
|
||||
Reference in New Issue
Block a user