Compare commits

..

7 Commits

Author SHA1 Message Date
yhirose 89740a808d Added a contributor to README 2020-01-28 06:34:10 -05:00
yhirose 2377a20e0b Merge pull request #340 from vitalyster/head_static
HEAD support for static file server
2020-01-28 06:32:32 -05:00
Vitaly Takmazov 5e43680486 HEAD support for static file server 2020-01-28 12:00:27 +03:00
yhirose 79df842cc5 Updated README 2020-01-26 18:34:50 -05:00
yhirose 48a4a5812e Merge pull request #338 from TheMaverickProgrammer/master
fixed missing import
2020-01-25 20:44:59 -05:00
TheMaverickProgrammer a7a6df49a4 Update split.py 2020-01-25 17:19:15 -06:00
TheMaverickProgrammer e932c7e1ec Update split.py
now works with legacy Python ( < 3.0)
2020-01-25 17:17:34 -06:00
4 changed files with 68 additions and 9 deletions
+44 -3
View File
@@ -349,8 +349,6 @@ std::shared_ptr<httplib::Response> res =
![progress](https://user-images.githubusercontent.com/236374/33138910-495c4ecc-cf86-11e7-8693-2fc6d09615c4.gif)
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)
+6 -5
View File
@@ -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
+9 -1
View File
@@ -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')
+9
View File
@@ -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);