|
|
@ -1,5 +1,5 @@ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-2020, The PurpleI2P Project |
|
|
|
* Copyright (c) 2013-2021, The PurpleI2P Project |
|
|
|
* |
|
|
|
* |
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3 |
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3 |
|
|
|
* |
|
|
|
* |
|
|
@ -9,12 +9,15 @@ |
|
|
|
#include <algorithm> |
|
|
|
#include <algorithm> |
|
|
|
#include <utility> |
|
|
|
#include <utility> |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
#include <ctime> |
|
|
|
#include "util.h" |
|
|
|
#include "util.h" |
|
|
|
|
|
|
|
#include "Base.h" |
|
|
|
#include "HTTP.h" |
|
|
|
#include "HTTP.h" |
|
|
|
#include <ctime> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace i2p { |
|
|
|
namespace i2p |
|
|
|
namespace http { |
|
|
|
{ |
|
|
|
|
|
|
|
namespace http |
|
|
|
|
|
|
|
{ |
|
|
|
const std::vector<std::string> HTTP_METHODS = { |
|
|
|
const std::vector<std::string> HTTP_METHODS = { |
|
|
|
"GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "CONNECT", // HTTP basic methods
|
|
|
|
"GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "CONNECT", // HTTP basic methods
|
|
|
|
"COPY", "LOCK", "MKCOL", "MOVE", "PROPFIND", "PROPPATCH", "UNLOCK", "SEARCH" // WebDAV methods, for SEARCH see rfc5323
|
|
|
|
"COPY", "LOCK", "MKCOL", "MOVE", "PROPFIND", "PROPPATCH", "UNLOCK", "SEARCH" // WebDAV methods, for SEARCH see rfc5323
|
|
|
@ -471,12 +474,15 @@ namespace http { |
|
|
|
return ptr; |
|
|
|
return ptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::string UrlDecode(const std::string& data, bool allow_null) { |
|
|
|
std::string UrlDecode(const std::string& data, bool allow_null) |
|
|
|
|
|
|
|
{ |
|
|
|
std::string decoded(data); |
|
|
|
std::string decoded(data); |
|
|
|
size_t pos = 0; |
|
|
|
size_t pos = 0; |
|
|
|
while ((pos = decoded.find('%', pos)) != std::string::npos) { |
|
|
|
while ((pos = decoded.find('%', pos)) != std::string::npos) |
|
|
|
|
|
|
|
{ |
|
|
|
char c = strtol(decoded.substr(pos + 1, 2).c_str(), NULL, 16); |
|
|
|
char c = strtol(decoded.substr(pos + 1, 2).c_str(), NULL, 16); |
|
|
|
if (c == '\0' && !allow_null) { |
|
|
|
if (c == '\0' && !allow_null) |
|
|
|
|
|
|
|
{ |
|
|
|
pos += 3; |
|
|
|
pos += 3; |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
@ -486,9 +492,11 @@ namespace http { |
|
|
|
return decoded; |
|
|
|
return decoded; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool MergeChunkedResponse (std::istream& in, std::ostream& out) { |
|
|
|
bool MergeChunkedResponse (std::istream& in, std::ostream& out) |
|
|
|
|
|
|
|
{ |
|
|
|
std::string hexLen; |
|
|
|
std::string hexLen; |
|
|
|
while (!in.eof ()) { |
|
|
|
while (!in.eof ()) |
|
|
|
|
|
|
|
{ |
|
|
|
std::getline (in, hexLen); |
|
|
|
std::getline (in, hexLen); |
|
|
|
errno = 0; |
|
|
|
errno = 0; |
|
|
|
long int len = strtoul(hexLen.c_str(), (char **) NULL, 16); |
|
|
|
long int len = strtoul(hexLen.c_str(), (char **) NULL, 16); |
|
|
@ -506,5 +514,12 @@ namespace http { |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string CreateBasicAuthorizationString (const std::string& user, const std::string& pass) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (user.empty () && pass.empty ()) return ""; |
|
|
|
|
|
|
|
return "Basic " + i2p::data::ToBase64Standard (user + ":" + pass); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // http
|
|
|
|
} // http
|
|
|
|
} // i2p
|
|
|
|
} // i2p
|
|
|
|