Skip to content

Commit

Permalink
Using HTTP when TLS verification is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
xfangfang committed Jan 17, 2025
1 parent a8a588b commit 6b125c3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 30 deletions.
17 changes: 0 additions & 17 deletions scripts/psv/curl/fix_curlformoption.patch

This file was deleted.

16 changes: 8 additions & 8 deletions wiliwili/include/api/bilibili/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ namespace bilibili {

namespace Api {

const std::string _apiBase = "https://api.bilibili.com";
const std::string _appBase = "https://app.bilibili.com";
const std::string _vcBase = "https://api.vc.bilibili.com";
const std::string _bvcBase = "https://bvc.bilivideo.com";
const std::string _liveBase = "https://api.live.bilibili.com";
const std::string _passBase = "https://passport.bilibili.com";
const std::string _bangumiBase = "https://bangumi.bilibili.com";
const std::string _grpcBase = "https://grpc.biliapi.net";
const std::string _apiBase = "api.bilibili.com";
const std::string _appBase = "app.bilibili.com";
const std::string _vcBase = "api.vc.bilibili.com";
const std::string _bvcBase = "bvc.bilivideo.com";
const std::string _liveBase = "api.live.bilibili.com";
const std::string _passBase = "passport.bilibili.com";
const std::string _bangumiBase = "bangumi.bilibili.com";
const std::string _grpcBase = "grpc.biliapi.net";

/// ===
/// 视频API
Expand Down
7 changes: 5 additions & 2 deletions wiliwili/include/api/bilibili/util/http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class HTTP {
static inline int TIMEOUT = 10000;
static inline cpr::Proxies PROXIES;
static inline cpr::VerifySsl VERIFY;
static inline std::string PROTOCOL = "https://";

static cpr::Response get(const std::string& url, const cpr::Parameters& parameters = {}, int timeout = 10000);

Expand All @@ -60,7 +61,8 @@ class HTTP {
}
callback(r);
},
cpr::Url{url}, parameters, payload, CPR_HTTP_BASE);
cpr::Url{pystring::startswith(url, "http") ? url : HTTP::PROTOCOL + url},
parameters, payload, CPR_HTTP_BASE);
}

static void __cpr_get(const std::string& url, const cpr::Parameters& parameters = {},
Expand All @@ -77,7 +79,8 @@ class HTTP {
}
callback(r);
},
cpr::Url{url}, parameters, CPR_HTTP_BASE);
cpr::Url{pystring::startswith(url, "http") ? url : HTTP::PROTOCOL + url},
parameters, CPR_HTTP_BASE);
}

template <typename ReturnType>
Expand Down
5 changes: 4 additions & 1 deletion wiliwili/source/api/bilibili.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ void BilibiliClient::setProxy(const std::string& httpProxy, const std::string& h
if (!httpProxy.empty() && !httpsProxy.empty()) HTTP::PROXIES = {{"http", httpProxy}, {"https", httpsProxy}};
}

void BilibiliClient::setTlsVerify(bool value) { HTTP::VERIFY = cpr::VerifySsl{value}; }
void BilibiliClient::setTlsVerify(bool value) {
HTTP::VERIFY = cpr::VerifySsl{value};
HTTP::PROTOCOL = value ? "https://" : "http://";
}

} // namespace bilibili
2 changes: 1 addition & 1 deletion wiliwili/source/api/home_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void BilibiliClient::get_pgc_all_filter(const std::function<void(PGCIndexFilters
cpr::MultiPerform multiperform;
for (auto& i : index_types) {
std::shared_ptr<cpr::Session> session = std::make_shared<cpr::Session>();
session->SetUrl(Api::PGCIndexFilter);
session->SetUrl(HTTP::PROTOCOL + Api::PGCIndexFilter);
session->SetParameters({{"type", "2"}, {"index_type", i}});
session->SetHeader(HTTP::HEADERS);
session->SetVerifySsl(HTTP::VERIFY);
Expand Down
2 changes: 1 addition & 1 deletion wiliwili/source/utils/image_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ std::shared_ptr<ImageHelper> ImageHelper::with(brls::Image* view) {
}

void ImageHelper::load(const std::string &url) {
this->imageUrl = url;
this->imageUrl = bilibili::HTTP::VERIFY ? url :pystring::replace(url, "https", "http", 1);

#ifdef BOREALIS_USE_GXM
std::vector<std::string> urls = pystring::rsplit(this->imageUrl, "@", 1);
Expand Down

0 comments on commit 6b125c3

Please sign in to comment.