@@ -447,6 +447,11 @@ WebTask WebRequest::send(std::string_view method, std::string_view url) {
447
447
curl_easy_setopt (curl, CURLOPT_URL, url.c_str ());
448
448
449
449
// 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
+
450
455
curl_easy_setopt (curl, CURLOPT_HTTP_VERSION, unwrapHttpVersion (impl->m_httpVersion ));
451
456
452
457
// Set request method
@@ -474,6 +479,8 @@ WebTask WebRequest::send(std::string_view method, std::string_view url) {
474
479
curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, impl->m_certVerification ? 1L : 0L );
475
480
curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 2L );
476
481
482
+ int sslOptions = 0 ;
483
+
477
484
if (impl->m_certVerification ) {
478
485
if (impl->m_CABundleContent .empty ()) {
479
486
impl->m_CABundleContent = CA_BUNDLE_CONTENT;
@@ -486,10 +493,14 @@ WebTask WebRequest::send(std::string_view method, std::string_view url) {
486
493
caBundleBlob.flags = CURL_BLOB_NOCOPY;
487
494
curl_easy_setopt (curl, CURLOPT_CAINFO_BLOB, &caBundleBlob);
488
495
// Also add the native CA, for good measure
489
- curl_easy_setopt (curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA) ;
496
+ sslOptions |= CURLSSLOPT_NATIVE_CA;
490
497
}
491
498
}
492
499
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
+
493
504
// Transfer body
494
505
curl_easy_setopt (curl, CURLOPT_NOBODY, impl->m_transferBody ? 0L : 1L );
495
506
@@ -550,6 +561,46 @@ WebTask WebRequest::send(std::string_view method, std::string_view url) {
550
561
// Do not fail if response code is 4XX or 5XX
551
562
curl_easy_setopt (curl, CURLOPT_FAILONERROR, 0L );
552
563
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
+
553
604
// If an error happens, we want to get a more specific description of the issue
554
605
char errorBuf[CURL_ERROR_SIZE];
555
606
errorBuf[0 ] = ' \0 ' ;
@@ -625,7 +676,13 @@ WebTask WebRequest::send(std::string_view method, std::string_view url) {
625
676
else {
626
677
std::string const err = curl_easy_strerror (curlResponse);
627
678
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
+ );
629
686
}
630
687
}
631
688
0 commit comments