mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-09 21:17:18 +03:00
make it fit in allocated space
This commit is contained in:
@@ -15,7 +15,9 @@
|
||||
#include "ByteStream.h"
|
||||
#include "SocketStream.h"
|
||||
#include "URLParser.h"
|
||||
#ifndef BELL_DISABLE_FMT
|
||||
#include "fmt/core.h"
|
||||
#endif
|
||||
#include "picohttpparser.h"
|
||||
|
||||
namespace bell {
|
||||
@@ -29,11 +31,19 @@ class HTTPClient {
|
||||
// Helper over ValueHeader, formatting a HTTP bytes range
|
||||
struct RangeHeader {
|
||||
static ValueHeader range(int32_t from, int32_t to) {
|
||||
#ifndef BELL_DISABLE_FMT
|
||||
return ValueHeader{"Range", fmt::format("bytes={}-{}", from, to)};
|
||||
#else
|
||||
return ValueHeader{"Range", "bytes=" + std::to_string(from) + "-" + std::to_string(to) };
|
||||
#endif
|
||||
}
|
||||
|
||||
static ValueHeader last(int32_t nbytes) {
|
||||
#ifndef BELL_DISABLE_FMT
|
||||
return ValueHeader{"Range", fmt::format("bytes=-{}", nbytes)};
|
||||
#else
|
||||
return ValueHeader{"Range", "bytes=-" + std::to_string(nbytes)};
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -58,16 +58,23 @@ class URLParser {
|
||||
|
||||
std::string schema = "http";
|
||||
std::string path;
|
||||
std::regex urlParseRegex = std::regex(
|
||||
"^(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(\\?(?:[^#]*))?(#(?:.*))?");
|
||||
#ifdef BELL_DISABLE_REGEX
|
||||
void parse(const char* url, std::vector<std::string>& match);
|
||||
#else
|
||||
static const std::regex urlParseRegex;
|
||||
#endif
|
||||
|
||||
static URLParser parse(const std::string& url) {
|
||||
URLParser parser;
|
||||
|
||||
// apply parser.urlParseRegex to url
|
||||
#ifdef BELL_DISABLE_REGEX
|
||||
std::vector<std::string> match(6);
|
||||
parser.parse(url.c_str(), match);
|
||||
#else
|
||||
std::cmatch match;
|
||||
|
||||
std::regex_match(url.c_str(), match, parser.urlParseRegex);
|
||||
#endif
|
||||
|
||||
if (match.size() < 3) {
|
||||
throw std::invalid_argument("Invalid URL");
|
||||
|
||||
Reference in New Issue
Block a user