Skip to content

Commit ec34df6

Browse files
committed
fix more schannel issues, add more network debugging
1 parent e0c1774 commit ec34df6

File tree

1 file changed

+59
-2
lines changed

1 file changed

+59
-2
lines changed

loader/src/utils/web.cpp

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,11 @@ WebTask WebRequest::send(std::string_view method, std::string_view url) {
447447
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
448448

449449
// Set HTTP version
450+
auto useHttp1 = Loader::get()->getLaunchFlag("use-http1");
451+
if (impl->m_httpVersion == HttpVersion::DEFAULT && useHttp1) {
452+
impl->m_httpVersion = HttpVersion::VERSION_1_1; // Force HTTP/1.1 if the flag is set
453+
}
454+
450455
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, unwrapHttpVersion(impl->m_httpVersion));
451456

452457
// Set request method
@@ -474,6 +479,8 @@ WebTask WebRequest::send(std::string_view method, std::string_view url) {
474479
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, impl->m_certVerification ? 1L : 0L);
475480
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
476481

482+
int sslOptions = 0;
483+
477484
if (impl->m_certVerification) {
478485
if (impl->m_CABundleContent.empty()) {
479486
impl->m_CABundleContent = CA_BUNDLE_CONTENT;
@@ -486,10 +493,14 @@ WebTask WebRequest::send(std::string_view method, std::string_view url) {
486493
caBundleBlob.flags = CURL_BLOB_NOCOPY;
487494
curl_easy_setopt(curl, CURLOPT_CAINFO_BLOB, &caBundleBlob);
488495
// Also add the native CA, for good measure
489-
curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
496+
sslOptions |= CURLSSLOPT_NATIVE_CA;
490497
}
491498
}
492499

500+
// weird windows stuff, don't remove if we still use schannel!
501+
GEODE_WINDOWS(sslOptions |= CURLSSLOPT_REVOKE_BEST_EFFORT);
502+
curl_easy_setopt(curl, CURLOPT_SSL_OPTIONS, sslOptions);
503+
493504
// Transfer body
494505
curl_easy_setopt(curl, CURLOPT_NOBODY, impl->m_transferBody ? 0L : 1L);
495506

@@ -550,6 +561,46 @@ WebTask WebRequest::send(std::string_view method, std::string_view url) {
550561
// Do not fail if response code is 4XX or 5XX
551562
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 0L);
552563

564+
// Verbose logging
565+
if (Mod::get()->getSettingValue<bool>("verbose-curl-logs")) {
566+
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
567+
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, +[](CURL* handle, curl_infotype type, char* data, size_t size, void* clientp) {
568+
while (size > 0 && (data[size - 1] == '\n' || data[size - 1] == '\r')) {
569+
size--; // remove trailing newline
570+
}
571+
572+
switch (type) {
573+
case CURLINFO_TEXT:
574+
log::debug("[Curl] {}", std::string_view(data, size));
575+
break;
576+
case CURLINFO_HEADER_IN:
577+
log::debug("[Curl] Header in: {}", std::string_view(data, size));
578+
break;
579+
case CURLINFO_HEADER_OUT:
580+
log::debug("[Curl] Header out: {}", std::string_view(data, size));
581+
break;
582+
case CURLINFO_DATA_IN:
583+
log::debug("[Curl] Data in ({} bytes)", size);
584+
break;
585+
case CURLINFO_DATA_OUT:
586+
log::debug("[Curl] Data out ({} bytes)", size);
587+
break;
588+
case CURLINFO_SSL_DATA_IN:
589+
log::debug("[Curl] SSL data in ({} bytes)", size);
590+
break;
591+
case CURLINFO_SSL_DATA_OUT:
592+
log::debug("[Curl] SSL data out ({} bytes)", size);
593+
break;
594+
case CURLINFO_END:
595+
log::debug("[Curl] End of info");
596+
break;
597+
default:
598+
log::debug("[Curl] Unknown info type: {}", static_cast<int>(type));
599+
break;
600+
}
601+
});
602+
}
603+
553604
// If an error happens, we want to get a more specific description of the issue
554605
char errorBuf[CURL_ERROR_SIZE];
555606
errorBuf[0] = '\0';
@@ -625,7 +676,13 @@ WebTask WebRequest::send(std::string_view method, std::string_view url) {
625676
else {
626677
std::string const err = curl_easy_strerror(curlResponse);
627678
log::error("cURL failure, error: {}", err);
628-
return impl->makeError(-1, "Curl failed: " + err);
679+
log::warn("Error buffer: {}", errorBuf);
680+
return impl->makeError(
681+
-1,
682+
!*errorBuf ?
683+
fmt::format("Curl failed: {}", err)
684+
: fmt::format("Curl failed: {} ({})", err, errorBuf)
685+
);
629686
}
630687
}
631688

0 commit comments

Comments
 (0)