mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2024-11-08 01:10:40 +00:00
fix http unit test SIGBUS in os x
This commit is contained in:
parent
0a83d8e6a0
commit
47ce2398a4
25
HTTP.cpp
25
HTTP.cpp
@ -10,21 +10,20 @@
|
|||||||
|
|
||||||
namespace i2p {
|
namespace i2p {
|
||||||
namespace http {
|
namespace http {
|
||||||
const char *HTTP_METHODS[] = {
|
const std::vector<std::string> HTTP_METHODS = {
|
||||||
"GET", "HEAD", "POST", "PUT", "PATCH",
|
"GET", "HEAD", "POST", "PUT", "PATCH",
|
||||||
"DELETE", "OPTIONS", "CONNECT",
|
"DELETE", "OPTIONS", "CONNECT"
|
||||||
NULL
|
|
||||||
};
|
};
|
||||||
const char *HTTP_VERSIONS[] = {
|
const std::vector<std::string> HTTP_VERSIONS = {
|
||||||
"HTTP/1.0", "HTTP/1.1", NULL
|
"HTTP/1.0", "HTTP/1.1"
|
||||||
};
|
};
|
||||||
|
|
||||||
bool in_cstr_array(const char **haystack, const char *needle) {
|
inline bool is_http_version(const std::string & str) {
|
||||||
for (const char *p = haystack[0]; p != NULL; p++) {
|
return std::find(HTTP_VERSIONS.begin(), HTTP_VERSIONS.end(), str) != std::end(HTTP_VERSIONS);
|
||||||
if (strcmp(p, needle) == 0)
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
inline bool is_http_method(const std::string & str) {
|
||||||
|
return std::find(HTTP_METHODS.begin(), HTTP_METHODS.end(), str) != std::end(HTTP_METHODS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void strsplit(const std::string & line, std::vector<std::string> &tokens, char delim, std::size_t limit = 0) {
|
void strsplit(const std::string & line, std::vector<std::string> &tokens, char delim, std::size_t limit = 0) {
|
||||||
@ -205,9 +204,9 @@ namespace http {
|
|||||||
strsplit(line, tokens, ' ');
|
strsplit(line, tokens, ' ');
|
||||||
if (tokens.size() != 3)
|
if (tokens.size() != 3)
|
||||||
return -1;
|
return -1;
|
||||||
if (!in_cstr_array(HTTP_METHODS, tokens[0].c_str()))
|
if (!is_http_method(tokens[0]))
|
||||||
return -1;
|
return -1;
|
||||||
if (!in_cstr_array(HTTP_VERSIONS, tokens[2].c_str()))
|
if (!is_http_version(tokens[2]))
|
||||||
return -1;
|
return -1;
|
||||||
if (!url.parse(tokens[1]))
|
if (!url.parse(tokens[1]))
|
||||||
return -1;
|
return -1;
|
||||||
@ -288,7 +287,7 @@ namespace http {
|
|||||||
strsplit(line, tokens, ' ', 3);
|
strsplit(line, tokens, ' ', 3);
|
||||||
if (tokens.size() != 3)
|
if (tokens.size() != 3)
|
||||||
return -1;
|
return -1;
|
||||||
if (!in_cstr_array(HTTP_VERSIONS, tokens[0].c_str()))
|
if (!is_http_version(tokens[0]))
|
||||||
return -1;
|
return -1;
|
||||||
code = atoi(tokens[1].c_str());
|
code = atoi(tokens[1].c_str());
|
||||||
if (code < 100 || code >= 600)
|
if (code < 100 || code >= 600)
|
||||||
|
4
HTTP.h
4
HTTP.h
@ -19,8 +19,8 @@ namespace i2p {
|
|||||||
namespace http {
|
namespace http {
|
||||||
const char CRLF[] = "\r\n"; /**< HTTP line terminator */
|
const char CRLF[] = "\r\n"; /**< HTTP line terminator */
|
||||||
const char HTTP_EOH[] = "\r\n\r\n"; /**< HTTP end-of-headers mark */
|
const char HTTP_EOH[] = "\r\n\r\n"; /**< HTTP end-of-headers mark */
|
||||||
extern const char *HTTP_METHODS[]; /**< list of valid HTTP methods */
|
extern const std::vector<std::string> HTTP_METHODS; /**< list of valid HTTP methods */
|
||||||
extern const char *HTTP_VERSIONS[]; /**< list of valid HTTP versions */
|
extern const std::vector<std::string> HTTP_VERSIONS; /**< list of valid HTTP versions */
|
||||||
|
|
||||||
struct URL {
|
struct URL {
|
||||||
std::string schema;
|
std::string schema;
|
||||||
|
Loading…
Reference in New Issue
Block a user