mirror of
https://github.com/yhirose/cpp-httplib
synced 2024-11-21 14:29:10 -07:00
Code format
This commit is contained in:
parent
40db42108f
commit
e9c6c6e609
2 changed files with 59 additions and 65 deletions
117
httplib.h
117
httplib.h
|
@ -192,6 +192,7 @@ using socket_t = int;
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -203,7 +204,6 @@ using socket_t = int;
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <iomanip>
|
|
||||||
|
|
||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
|
@ -1457,26 +1457,19 @@ inline bool is_valid_path(const std::string &path) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string encode_query_param(const std::string &value){
|
inline std::string encode_query_param(const std::string &value) {
|
||||||
std::ostringstream escaped;
|
std::ostringstream escaped;
|
||||||
escaped.fill('0');
|
escaped.fill('0');
|
||||||
escaped << std::hex;
|
escaped << std::hex;
|
||||||
|
|
||||||
for (char const &c: value) {
|
for (char const &c : value) {
|
||||||
if (std::isalnum(c) ||
|
if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '!' ||
|
||||||
c == '-' ||
|
c == '~' || c == '*' || c == '\'' || c == '(' || c == ')') {
|
||||||
c == '_' ||
|
|
||||||
c == '.' ||
|
|
||||||
c == '!' ||
|
|
||||||
c == '~' ||
|
|
||||||
c == '*' ||
|
|
||||||
c == '\'' ||
|
|
||||||
c == '(' ||
|
|
||||||
c == ')') {
|
|
||||||
escaped << c;
|
escaped << c;
|
||||||
} else {
|
} else {
|
||||||
escaped << std::uppercase;
|
escaped << std::uppercase;
|
||||||
escaped << '%' << std::setw(2) << static_cast<int>(static_cast<unsigned char>(c));
|
escaped << '%' << std::setw(2)
|
||||||
|
<< static_cast<int>(static_cast<unsigned char>(c));
|
||||||
escaped << std::nouppercase;
|
escaped << std::nouppercase;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2175,9 +2168,9 @@ inline unsigned int str2tag(const std::string &s) {
|
||||||
|
|
||||||
namespace udl {
|
namespace udl {
|
||||||
|
|
||||||
inline constexpr unsigned int operator"" _(const char *s, size_t l) {
|
inline constexpr unsigned int operator"" _(const char *s, size_t l) {
|
||||||
return str2tag_core(s, l, 0);
|
return str2tag_core(s, l, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace udl
|
} // namespace udl
|
||||||
|
|
||||||
|
@ -2192,56 +2185,56 @@ find_content_type(const std::string &path,
|
||||||
using udl::operator""_;
|
using udl::operator""_;
|
||||||
|
|
||||||
switch (str2tag(ext)) {
|
switch (str2tag(ext)) {
|
||||||
default: return nullptr;
|
default: return nullptr;
|
||||||
case "css"_: return "text/css";
|
case "css"_: return "text/css";
|
||||||
case "csv"_: return "text/csv";
|
case "csv"_: return "text/csv";
|
||||||
case "txt"_: return "text/plain";
|
case "txt"_: return "text/plain";
|
||||||
case "vtt"_: return "text/vtt";
|
case "vtt"_: return "text/vtt";
|
||||||
case "htm"_:
|
case "htm"_:
|
||||||
case "html"_: return "text/html";
|
case "html"_: return "text/html";
|
||||||
|
|
||||||
case "apng"_: return "image/apng";
|
case "apng"_: return "image/apng";
|
||||||
case "avif"_: return "image/avif";
|
case "avif"_: return "image/avif";
|
||||||
case "bmp"_: return "image/bmp";
|
case "bmp"_: return "image/bmp";
|
||||||
case "gif"_: return "image/gif";
|
case "gif"_: return "image/gif";
|
||||||
case "png"_: return "image/png";
|
case "png"_: return "image/png";
|
||||||
case "svg"_: return "image/svg+xml";
|
case "svg"_: return "image/svg+xml";
|
||||||
case "webp"_: return "image/webp";
|
case "webp"_: return "image/webp";
|
||||||
case "ico"_: return "image/x-icon";
|
case "ico"_: return "image/x-icon";
|
||||||
case "tif"_: return "image/tiff";
|
case "tif"_: return "image/tiff";
|
||||||
case "tiff"_: return "image/tiff";
|
case "tiff"_: return "image/tiff";
|
||||||
case "jpg"_:
|
case "jpg"_:
|
||||||
case "jpeg"_: return "image/jpeg";
|
case "jpeg"_: return "image/jpeg";
|
||||||
|
|
||||||
case "mp4"_: return "video/mp4";
|
case "mp4"_: return "video/mp4";
|
||||||
case "mpeg"_: return "video/mpeg";
|
case "mpeg"_: return "video/mpeg";
|
||||||
case "webm"_: return "video/webm";
|
case "webm"_: return "video/webm";
|
||||||
|
|
||||||
case "mp3"_: return "audio/mp3";
|
case "mp3"_: return "audio/mp3";
|
||||||
case "mpga"_: return "audio/mpeg";
|
case "mpga"_: return "audio/mpeg";
|
||||||
case "weba"_: return "audio/webm";
|
case "weba"_: return "audio/webm";
|
||||||
case "wav"_: return "audio/wave";
|
case "wav"_: return "audio/wave";
|
||||||
|
|
||||||
case "otf"_: return "font/otf";
|
case "otf"_: return "font/otf";
|
||||||
case "ttf"_: return "font/ttf";
|
case "ttf"_: return "font/ttf";
|
||||||
case "woff"_: return "font/woff";
|
case "woff"_: return "font/woff";
|
||||||
case "woff2"_: return "font/woff2";
|
case "woff2"_: return "font/woff2";
|
||||||
|
|
||||||
case "7z"_: return "application/x-7z-compressed";
|
case "7z"_: return "application/x-7z-compressed";
|
||||||
case "atom"_: return "application/atom+xml";
|
case "atom"_: return "application/atom+xml";
|
||||||
case "pdf"_: return "application/pdf";
|
case "pdf"_: return "application/pdf";
|
||||||
case "js"_:
|
case "js"_:
|
||||||
case "mjs"_: return "application/javascript";
|
case "mjs"_: return "application/javascript";
|
||||||
case "json"_: return "application/json";
|
case "json"_: return "application/json";
|
||||||
case "rss"_: return "application/rss+xml";
|
case "rss"_: return "application/rss+xml";
|
||||||
case "tar"_: return "application/x-tar";
|
case "tar"_: return "application/x-tar";
|
||||||
case "xht"_:
|
case "xht"_:
|
||||||
case "xhtml"_: return "application/xhtml+xml";
|
case "xhtml"_: return "application/xhtml+xml";
|
||||||
case "xslt"_: return "application/xslt+xml";
|
case "xslt"_: return "application/xslt+xml";
|
||||||
case "xml"_: return "application/xml";
|
case "xml"_: return "application/xml";
|
||||||
case "gz"_: return "application/gzip";
|
case "gz"_: return "application/gzip";
|
||||||
case "zip"_: return "application/zip";
|
case "zip"_: return "application/zip";
|
||||||
case "wasm"_: return "application/wasm";
|
case "wasm"_: return "application/wasm";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,16 +46,17 @@ TEST(StartupTest, WSAStartup) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TEST(EncodeQueryParamTest, ParseUnescapedChararactersTest){
|
TEST(EncodeQueryParamTest, ParseUnescapedChararactersTest) {
|
||||||
string unescapedCharacters = "-_.!~*'()";
|
string unescapedCharacters = "-_.!~*'()";
|
||||||
|
|
||||||
EXPECT_EQ(detail::encode_query_param(unescapedCharacters), "-_.!~*'()");
|
EXPECT_EQ(detail::encode_query_param(unescapedCharacters), "-_.!~*'()");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(EncodeQueryParamTest, ParseReservedCharactersTest){
|
TEST(EncodeQueryParamTest, ParseReservedCharactersTest) {
|
||||||
string reservedCharacters = ";,/?:@&=+$";
|
string reservedCharacters = ";,/?:@&=+$";
|
||||||
|
|
||||||
EXPECT_EQ(detail::encode_query_param(reservedCharacters), "%3B%2C%2F%3F%3A%40%26%3D%2B%24");
|
EXPECT_EQ(detail::encode_query_param(reservedCharacters),
|
||||||
|
"%3B%2C%2F%3F%3A%40%26%3D%2B%24");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(TrimTests, TrimStringTests) {
|
TEST(TrimTests, TrimStringTests) {
|
||||||
|
|
Loading…
Reference in a new issue