check url scheme

This commit is contained in:
Chunting Gu
2021-06-22 10:16:58 +08:00
parent 26bb6b341a
commit 326a3ea215
4 changed files with 70 additions and 10 deletions
+20
View File
@@ -14,6 +14,8 @@
#endif // defined(_WIN32) || defined(_WIN64)
#endif // WEBCC_ENABLE_SSL
#include "boost/algorithm/string.hpp"
#include "webcc/base64.h"
#include "webcc/logger.h"
#include "webcc/url.h"
@@ -193,6 +195,10 @@ ResponsePtr ClientSession::Send(RequestPtr request, bool stream,
throw Error{ Error::kStateError, "Loop is not running" };
}
if (!CheckUrlScheme(request)) {
throw Error{ Error::kSyntaxError, "Invalid URL scheme" };
}
for (auto& h : headers_.data()) {
if (!request->HasHeader(h.first)) {
request->SetHeader(h.first, h.second);
@@ -229,6 +235,20 @@ void ClientSession::InitHeaders() {
headers_.Set(headers::kConnection, "Keep-Alive");
}
bool ClientSession::CheckUrlScheme(RequestPtr request) {
if (boost::iequals(request->url().scheme(), "http")) {
return true;
}
#if WEBCC_ENABLE_SSL
if (boost::iequals(request->url().scheme(), "https")) {
return true;
}
#endif // WEBCC_ENABLE_SSL
return false;
}
ResponsePtr ClientSession::DoSend(RequestPtr request, bool stream,
ProgressCallback callback) {
const ClientPool::Key key{ request->url() };