OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::Http Class Reference

Represetns a Http request. More...

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Utils/Http.hpp>

Inheritance diagram for Slic3r::Http:
Collaboration diagram for Slic3r::Http:

Classes

struct  Progress
struct  priv

Public Types

typedef std::shared_ptr< Http > Ptr
typedef std::function< void(std::string, unsigned)> CompleteFn
typedef std::function< void(std::string, std::string, unsigned)> ErrorFn
typedef std::function< void(Progress, bool &)> ProgressFn
typedef std::function< void(std::string)> IPResolveFn
typedef std::function< void(std::string headers)> HeaderCallbackFn

Public Member Functions

 Http (Http &&other)
 ~Http ()
 Http (const Http &)=delete
Http & operator= (const Http &)=delete
Http & operator= (Http &&)=delete
Http & timeout_connect (long timeout)
Http & timeout_max (long timeout)
Http & size_limit (size_t sizeLimit)
Http & set_range (const std::string &range)
Http & header (std::string name, const std::string &value)
Http & headers_reset ()
Http & remove_header (std::string name)
Http & auth_digest (const std::string &user, const std::string &password)
Http & auth_basic (const std::string &user, const std::string &password)
Http & ca_file (const std::string &filename)
Http & tls_verify (bool enable)
Http & form_clear ()
Http & form_add (const std::string &name, const std::string &contents)
Http & form_add_file (const std::string &name, const boost::filesystem::path &path, boost::filesystem::ifstream::off_type offset=0, size_t length=0)
Http & mime_form_add_text (std::string &name, std::string &value)
Http & mime_form_add_file (std::string &name, const char *path)
Http & form_add_file (const std::wstring &name, const boost::filesystem::path &path, boost::filesystem::ifstream::off_type offset=0, size_t length=0)
Http & form_add_file (const std::string &name, const boost::filesystem::path &path, const std::string &filename, boost::filesystem::ifstream::off_type offset=0, size_t length=0)
Http & set_post_body (const boost::filesystem::path &path)
Http & set_post_body (const std::string &body)
Http & set_put_body (const boost::filesystem::path &path)
Http & set_del_body (const std::string &body)
Http & on_complete (CompleteFn fn)
Http & on_error (ErrorFn fn)
Http & on_progress (ProgressFn fn)
Http & on_ip_resolve (IPResolveFn fn)
Http & on_header_callback (HeaderCallbackFn fn)
Ptr perform ()
void perform_sync ()
void cancel ()
void print () const

Static Public Member Functions

static Http get (std::string url)
static Http post (std::string url)
static Http put (std::string url)
static Http del (std::string url)
static Http put2 (std::string url)
static Http patch (std::string url)
static void set_extra_headers (std::map< std::string, std::string > headers)
static std::map< std::string, std::string > get_extra_headers ()
static bool ca_file_supported ()
static std::string tls_global_init ()
static std::string tls_system_cert_store ()
static std::string url_encode (const std::string &str)
static std::string url_decode (const std::string &str)
static std::string get_filename_from_url (const std::string &url)
static std::string get_host_from_url (const std::string &url, std::string *port=nullptr)
static std::string get_host_header_value (const std::string &url)

Private Member Functions

 Http (const std::string &url)

Private Attributes

std::unique_ptr< priv > p

Detailed Description

Represetns a Http request.

Member Typedef Documentation

◆ CompleteFn

typedef std::function<void(std::string , unsigned )> Slic3r::Http::CompleteFn

◆ ErrorFn

typedef std::function<void(std::string , std::string , unsigned )> Slic3r::Http::ErrorFn

◆ HeaderCallbackFn

typedef std::function<void(std::string headers)> Slic3r::Http::HeaderCallbackFn

◆ IPResolveFn

typedef std::function<void(std::string)> Slic3r::Http::IPResolveFn

◆ ProgressFn

typedef std::function<void(Progress, bool& )> Slic3r::Http::ProgressFn

◆ Ptr

typedef std::shared_ptr<Http> Slic3r::Http::Ptr

Constructor & Destructor Documentation

◆ Http() [1/3]

Slic3r::Http::Http ( Http && other)
551: p(std::move(other.p)) {}
std::unique_ptr< priv > p
Definition Http.hpp:214

References Http(), and p.

Referenced by Http(), Http(), auth_basic(), auth_digest(), ca_file(), del(), form_add(), form_add_file(), form_add_file(), form_add_file(), form_clear(), get(), header(), headers_reset(), mime_form_add_file(), mime_form_add_text(), on_complete(), on_error(), on_header_callback(), on_ip_resolve(), on_progress(), operator=(), operator=(), patch(), post(), put(), put2(), remove_header(), set_del_body(), set_post_body(), set_post_body(), set_put_body(), set_range(), size_limit(), timeout_connect(), timeout_max(), and tls_verify().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~Http()

Slic3r::Http::~Http ( )
554{
555 assert(! p || ! p->putFile);
556 if (p && p->io_thread.joinable()) {
557 p->io_thread.detach();
558 }
559}

References p.

◆ Http() [2/3]

Slic3r::Http::Http ( const Http & )
delete

References Http().

Here is the call graph for this function:

◆ Http() [3/3]

Slic3r::Http::Http ( const std::string & url)
private
541 : p(new priv(url)) {
542
543 std::lock_guard<std::mutex> l(g_mutex);
544 for (auto it = extra_headers.begin(); it != extra_headers.end(); it++)
545 this->header(it->first, it->second);
546}
Http & header(std::string name, const std::string &value)
Definition Http.cpp:588
std::map< std::string, std::string > extra_headers
Definition Http.cpp:106
std::mutex g_mutex
Definition Http.cpp:107
Definition Http.cpp:121

References Slic3r::extra_headers, Slic3r::g_mutex, header(), and p.

Here is the call graph for this function:

Member Function Documentation

◆ auth_basic()

Http & Slic3r::Http::auth_basic ( const std::string & user,
const std::string & password )
637{
638 curl_easy_setopt(p->curl, CURLOPT_USERNAME, user.c_str());
639 curl_easy_setopt(p->curl, CURLOPT_PASSWORD, password.c_str());
640 curl_easy_setopt(p->curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
641
642 return *this;
643}

References Http(), and p.

Here is the call graph for this function:

◆ auth_digest()

Http & Slic3r::Http::auth_digest ( const std::string & user,
const std::string & password )
628{
629 curl_easy_setopt(p->curl, CURLOPT_USERNAME, user.c_str());
630 curl_easy_setopt(p->curl, CURLOPT_PASSWORD, password.c_str());
631 curl_easy_setopt(p->curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
632
633 return *this;
634}

References Http(), and p.

Here is the call graph for this function:

◆ ca_file()

Http & Slic3r::Http::ca_file ( const std::string & filename)
646{
647 if (p && priv::ca_file_supported(p->curl)) {
648 ::curl_easy_setopt(p->curl, CURLOPT_CAINFO, name.c_str());
649 }
650
651 return *this;
652}
static bool ca_file_supported(::CURL *curl)
Definition Http.cpp:234

References Http(), Slic3r::Http::priv::ca_file_supported(), and p.

Here is the call graph for this function:

◆ ca_file_supported()

bool Slic3r::Http::ca_file_supported ( )
static
944{
945 ::CURL *curl = ::curl_easy_init();
946 bool res = priv::ca_file_supported(curl);
947 if (curl != nullptr) { ::curl_easy_cleanup(curl); }
948 return res;
949}

References Slic3r::Http::priv::ca_file_supported().

Referenced by Slic3r::GUI::InputIpAddressDialog::InputIpAddressDialog(), Slic3r::GUI::PhysicalPrinterDialog::build_printhost_settings(), and Slic3r::GUI::InputIpAddressDialog::on_ok().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cancel()

void Slic3r::Http::cancel ( )
814{
815 if (p) { p->cancel.store(true); }
816}

References p.

◆ del()

Http Slic3r::Http::del ( std::string url)
static
924{
925 Http http{ std::move(url) };
926 http.p->method = "DELETE";
927 curl_easy_setopt(http.p->curl, CURLOPT_CUSTOMREQUEST, "DELETE");
928 return http;
929}
Http(Http &&other)
Definition Http.cpp:551
@ http
Definition IPrinterAgent.hpp:64

References Http(), and Slic3r::http.

Referenced by Slic3r::OrcaCloudServiceAgent::http_delete().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ form_add()

Http & Slic3r::Http::form_add ( const std::string & name,
const std::string & contents )
681{
682 if (p) {
683 ::curl_formadd(&p->form, &p->form_end,
684 CURLFORM_COPYNAME, name.c_str(),
685 CURLFORM_COPYCONTENTS, contents.c_str(),
686 CURLFORM_END
687 );
688 }
689
690 return *this;
691}

References Http(), and p.

Here is the call graph for this function:

◆ form_add_file() [1/3]

Http & Slic3r::Http::form_add_file ( const std::string & name,
const boost::filesystem::path & path,
boost::filesystem::ifstream::off_type offset = 0,
size_t length = 0 )

References Http(), Slic3r::length(), and Slic3r::offset().

Here is the call graph for this function:

◆ form_add_file() [2/3]

Http & Slic3r::Http::form_add_file ( const std::string & name,
const boost::filesystem::path & path,
const std::string & filename,
boost::filesystem::ifstream::off_type offset = 0,
size_t length = 0 )

References Http(), Slic3r::length(), and Slic3r::offset().

Here is the call graph for this function:

◆ form_add_file() [3/3]

Http & Slic3r::Http::form_add_file ( const std::wstring & name,
const boost::filesystem::path & path,
boost::filesystem::ifstream::off_type offset = 0,
size_t length = 0 )

References Http(), Slic3r::length(), and Slic3r::offset().

Here is the call graph for this function:

◆ form_clear()

Http & Slic3r::Http::form_clear ( )
664 {
665 if (p) {
666 if (p->form) {
667 ::curl_formfree(p->form);
668 p->form = nullptr;
669 p->form_end = nullptr;
670 }
671 for (auto &f : p->form_files) {
672 f.ifs.close();
673 }
674 p->form_files.clear();
675
676 }
677 return *this;
678}
static double f(double x, double z_sin, double z_cos, bool vertical, bool flip)
Definition FillGyroid.cpp:124

References Http(), Slic3r::f(), and p.

Here is the call graph for this function:

◆ get()

Http Slic3r::Http::get ( std::string url)
static
887{
888 return Http{std::move(url)};
889}

References Http().

Referenced by Slic3r::UltiMaker::auth_status(), Slic3r::PresetUpdater::priv::check_new_vendors(), Slic3r::GUI::GUI_App::check_new_version(), Slic3r::GUI::GUI_App::check_new_version_sf(), Slic3r::GUI::GUI_App::check_privacy_version(), Slic3r::Duet::connect(), Slic3r::UltiMaker::connect(), Slic3r::GUI::ScoreDialog::create_oss_thumbnail(), Slic3r::Duet::disconnect(), Slic3r::UltiMaker::disconnect(), Slic3r::SimplyPrint::do_chunk_upload(), Slic3r::CloudPluginService::download_cloud_plugin(), Slic3r::GUI::HMSQuery::download_hms_related(), Slic3r::GUI::GUI_App::download_plugin(), Slic3r::ElegooLink::elegoo_cc2_test(), Slic3r::ElegooLink::elegoo_test(), Slic3r::MoonrakerPrinterAgent::fetch_device_info(), Slic3r::QidiPrinterAgent::fetch_filament_dict(), Slic3r::SnapmakerPrinterAgent::fetch_filament_info(), Slic3r::MoonrakerPrinterAgent::fetch_hh_filament_info(), Slic3r::MoonrakerPrinterAgent::fetch_moonraker_filament_data(), Slic3r::MoonrakerPrinterAgent::fetch_object_list(), Slic3r::QidiPrinterAgent::fetch_slot_info(), Slic3r::GUI::get_error_message(), Slic3r::PresetUpdater::priv::get_file(), Slic3r::Repetier::get_groups(), Slic3r::GUI::get_hms_info_version(), Slic3r::GUI::FileGet::priv::get_perform(), Slic3r::ElegooLink::get_print_host_webui(), Slic3r::Obico::get_printers(), Slic3r::Repetier::get_printers(), Slic3r::Moonraker::get_storage(), Slic3r::PrusaLink::get_storage(), Slic3r::OrcaCloudServiceAgent::http_get(), Slic3r::GUI::Plater::import_model_id(), Slic3r::UltiMaker::is_authorized(), Slic3r::GUI::BindMachineDialog::on_show(), Slic3r::GUI::UnBindMachineDialog::on_show(), Slic3r::anonymous_namespace{CrealityHostDiscovery.cpp}::probe_info(), Slic3r::MoonrakerPrinterAgent::query_printer_status(), Slic3r::OrcaCloudServiceAgent::run_health_check(), Slic3r::Duet::start_print(), Slic3r::ESP3D::start_print(), Slic3r::UltiMaker::start_print(), Slic3r::GUI::NetworkTestDialog::start_test_url(), Slic3r::PresetUpdater::priv::sync_resources(), Slic3r::PresetUpdater::priv::sync_vendor_config(), Slic3r::PresetUpdater::priv::sync_version(), Slic3r::AstroBox::test(), Slic3r::CrealityPrint::test(), Slic3r::ESP3D::test(), Slic3r::FlashAir::test(), Slic3r::Moonraker::test(), Slic3r::Obico::test(), Slic3r::OctoPrint::test(), Slic3r::PrusaLink::test(), Slic3r::Repetier::test(), Slic3r::SimplyPrint::test(), Slic3r::UltiMaker::test(), Slic3r::PrusaLink::test_with_method_check(), and Slic3r::FlashAir::upload().

Here is the call graph for this function:

◆ get_extra_headers()

std::map< std::string, std::string > Slic3r::Http::get_extra_headers ( )
static
938{
939 std::lock_guard<std::mutex> l(g_mutex);
940 return extra_headers;
941}

References Slic3r::extra_headers, and Slic3r::g_mutex.

Referenced by Slic3r::PresetUpdater::priv::sync_plugins().

Here is the caller graph for this function:

◆ get_filename_from_url()

std::string Slic3r::Http::get_filename_from_url ( const std::string & url)
static
999{
1000 int end_pos = url.find_first_of('?');
1001 if (end_pos <= 0) return "";
1002 std::string path_url = url.substr(0, end_pos);
1003 int start_pos = path_url.find_last_of("/");
1004 if (start_pos < 0) return "";
1005 return path_url.substr(start_pos + 1, path_url.length() - start_pos - 1);
1006}

◆ get_host_from_url()

std::string Slic3r::Http::get_host_from_url ( const std::string & url,
std::string * port = nullptr )
static
1009{
1010 std::string url = url_in;
1011 if (url.find("//") == std::string::npos)
1012 url = "http://" + url;
1013
1014 if (port)
1015 port->clear();
1016 std::string out = url_in;
1017 CURLU *hurl = curl_url();
1018 if (hurl) {
1019 CURLUcode rc = curl_url_set(hurl, CURLUPART_URL, url.c_str(), 0);
1020 if (rc == CURLUE_OK) {
1021 char *host;
1022 rc = curl_url_get(hurl, CURLUPART_HOST, &host, 0);
1023 if (rc == CURLUE_OK) {
1024 out = host;
1025 curl_free(host);
1026 if (port) {
1027 char *pstr;
1028 rc = curl_url_get(hurl, CURLUPART_PORT, &pstr, 0);
1029 if (rc == CURLUE_OK && pstr) {
1030 *port = pstr;
1031 curl_free(pstr);
1032 }
1033 }
1034 } else
1035 BOOST_LOG_TRIVIAL(error) << "Http::get_host_from_url: failed to get host from URL " << url;
1036 } else
1037 BOOST_LOG_TRIVIAL(error) << "Http::get_host_from_url: failed to parse URL " << url;
1038 curl_url_cleanup(hurl);
1039 } else
1040 BOOST_LOG_TRIVIAL(error) << "Http::get_host_from_url: failed to allocate curl_url";
1041 return out;
1042}

Referenced by Slic3r::MachineObject::connect(), get_host_header_value(), Slic3r::GUI::InputIpAddressDialog::isValidEndpoint(), Slic3r::ElegooLink::loopUpload(), Slic3r::GUI::InputIpAddressDialog::on_ok(), Slic3r::ElegooLink::upload(), Slic3r::OctoPrint::upload(), and Slic3r::ws_connect().

Here is the caller graph for this function:

◆ get_host_header_value()

std::string Slic3r::Http::get_host_header_value ( const std::string & url)
static
1045{
1046 std::string port;
1047 std::string host = get_host_from_url(url, &port);
1048 if (!port.empty())
1049 host += ":" + port;
1050 return host;
1051}
static std::string get_host_from_url(const std::string &url, std::string *port=nullptr)
Definition Http.cpp:1008

References get_host_from_url().

Referenced by Slic3r::ElegooLink::elegoo_cc2_test(), Slic3r::ElegooLink::get_print_host_webui(), Slic3r::anonymous_namespace{ElegooLink.cpp}::lookup_cc2_serial_impl(), Slic3r::ElegooLink::loopUpload(), Slic3r::PrusaLink::post_inner(), Slic3r::PrusaLink::put_inner(), Slic3r::ElegooLink::upload_inner_with_host(), and Slic3r::OctoPrint::upload_inner_with_host().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ header()

Http & Slic3r::Http::header ( std::string name,
const std::string & value )
589{
590 if (!p) { return * this; }
591
592 if (name.size() > 0) {
593 name.append(": ").append(value);
594 } else {
595 name.push_back(':');
596 }
597 p->headerlist = curl_slist_append(p->headerlist, name.c_str());
598 return *this;
599}

References Http(), and p.

Referenced by Http(), Slic3r::GUI::GUI_App::download_plugin(), headers_reset(), and print().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ headers_reset()

Http & Slic3r::Http::headers_reset ( )
602{
603 if (!p) { return *this; }
604
605 ::curl_slist_free_all(p->headerlist);
606 p->headerlist = nullptr;
607 p->headerlist = curl_slist_append(p->headerlist, "Expect:");
608
609 std::lock_guard<std::mutex> l(g_mutex);
610 for (auto it = extra_headers.begin(); it != extra_headers.end(); ++it)
611 this->header(it->first, it->second);
612
613 return *this;
614}

References Http(), Slic3r::extra_headers, Slic3r::g_mutex, header(), and p.

Here is the call graph for this function:

◆ mime_form_add_file()

Http & Slic3r::Http::mime_form_add_file ( std::string & name,
const char * path )
707{
708 if (p) { p->mime_form_add_file(name.c_str(), path); }
709 return *this;
710}

References Http(), and p.

Here is the call graph for this function:

◆ mime_form_add_text()

Http & Slic3r::Http::mime_form_add_text ( std::string & name,
std::string & value )
701{
702 if (p) { p->mime_form_add_text(name.c_str(), value.c_str()); }
703 return *this;
704}

References Http(), and p.

Here is the call graph for this function:

◆ on_complete()

Http & Slic3r::Http::on_complete ( CompleteFn fn)
765{
766 if (p) { p->completefn = std::move(fn); }
767 return *this;
768}

References Http(), and p.

Referenced by Slic3r::GUI::GUI_App::download_plugin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_error()

Http & Slic3r::Http::on_error ( ErrorFn fn)
771{
772 if (p) { p->errorfn = std::move(fn); }
773 return *this;
774}

References Http(), and p.

Referenced by Slic3r::PresetUpdater::priv::check_new_vendors(), and Slic3r::PresetUpdater::priv::sync_vendor_config().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_header_callback()

Http & Slic3r::Http::on_header_callback ( HeaderCallbackFn fn)
789{
790 if (p) { p->headerfn = std::move(fn); }
791 return *this;
792}

References Http(), and p.

Referenced by Slic3r::GUI::FileGet::priv::get_perform().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_ip_resolve()

Http & Slic3r::Http::on_ip_resolve ( IPResolveFn fn)
783{
784 if (p) { p->ipresolvefn = std::move(fn); }
785 return *this;
786}

References Http(), and p.

Here is the call graph for this function:

◆ on_progress()

Http & Slic3r::Http::on_progress ( ProgressFn fn)
777{
778 if (p) { p->progressfn = std::move(fn); }
779 return *this;
780}

References Http(), and p.

Referenced by Slic3r::PresetUpdater::priv::check_new_vendors(), Slic3r::PresetUpdater::priv::get_file(), Slic3r::PresetUpdater::priv::sync_vendor_config(), and Slic3r::PresetUpdater::priv::sync_version().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=() [1/2]

Http & Slic3r::Http::operator= ( const Http & )
delete

References Http().

Here is the call graph for this function:

◆ operator=() [2/2]

Http & Slic3r::Http::operator= ( Http && )
delete

References Http(), and Slic3r::range().

Here is the call graph for this function:

◆ patch()

Http Slic3r::Http::patch ( std::string url)
static
916{
917 Http http{ std::move(url) };
918 http.p->method = "PATCH";
919 curl_easy_setopt(http.p->curl, CURLOPT_CUSTOMREQUEST, "PATCH");
920 return http;
921}

References Http(), and Slic3r::http.

Here is the call graph for this function:

◆ perform()

Http::Ptr Slic3r::Http::perform ( )
795{
796 auto self = std::make_shared<Http>(std::move(*this));
797
798 if (self->p) {
799 auto io_thread = std::thread([self](){
800 self->p->http_perform();
801 });
802 self->p->io_thread = std::move(io_thread);
803 }
804
805 return self;
806}

◆ perform_sync()

void Slic3r::Http::perform_sync ( )
809{
810 if (p) { p->http_perform(); }
811}

References p.

◆ post()

Http Slic3r::Http::post ( std::string url)
static
892{
893 Http http{std::move(url)};
894 http.p->method = "POST";
895 curl_easy_setopt(http.p->curl, CURLOPT_POST, 1L);
896 return http;
897}

References Http(), and Slic3r::http.

Referenced by Slic3r::PresetUpdater::priv::check_new_vendors(), Slic3r::SimplyPrint::do_api_call(), Slic3r::SimplyPrint::do_chunk_upload(), Slic3r::SimplyPrint::do_temp_upload(), Slic3r::UltiMaker::generate_auth_creds(), Slic3r::OrcaCloudServiceAgent::http_post(), Slic3r::OrcaCloudServiceAgent::http_post_auth(), Slic3r::OrcaCloudServiceAgent::http_post_token(), Slic3r::ElegooLink::loopUpload(), Slic3r::PrusaLink::post_inner(), Slic3r::GUI::OAuthJob::process(), Slic3r::Flashforge::request_local_api_json(), Slic3r::OrcaCloudServiceAgent::request_web_session_handoff(), Slic3r::C3DPrinterOS::send_form(), Slic3r::MoonrakerPrinterAgent::send_gcode_async(), Slic3r::MoonrakerPrinterAgent::send_gcode_sync(), Slic3r::GUI::SendSystemInfoDialog::send_info(), Slic3r::MoonrakerPrinterAgent::send_jsonrpc_command(), anonymous_namespace{3DPrinterOS.cpp}::TokenAuthDialog::SendRequest(), Slic3r::Duet::start_print(), Slic3r::Moonraker::start_print(), Slic3r::UltiMaker::start_print(), Slic3r::AstroBox::upload(), Slic3r::C3DPrinterOS::upload(), Slic3r::CrealityPrint::upload(), Slic3r::Duet::upload(), Slic3r::ESP3D::upload(), Slic3r::FlashAir::upload(), Slic3r::MKS::upload(), Slic3r::Moonraker::upload(), Slic3r::Obico::upload(), Slic3r::Repetier::upload(), Slic3r::UltiMaker::upload(), Slic3r::MoonrakerPrinterAgent::upload_gcode(), Slic3r::OctoPrint::upload_inner_with_host(), and Slic3r::Flashforge::upload_local_api().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print()

void Slic3r::Http::print ( ) const
819{
820 if (!p) {
821 BOOST_LOG_TRIVIAL(info) << "Http::print() - no request data";
822 return;
823 }
824
825 std::ostringstream cmd;
826 cmd << "curl";
827
828 // Method
829 if (p->method != "GET") {
830 cmd << " -X " << p->method;
831 }
832
833 // URL
834 cmd << " '" << p->url << "'";
835
836 // Headers (iterate through curl_slist)
837 ::curl_slist *header = p->headerlist;
838 while (header) {
839 // Skip empty "Expect:" header we add by default
840 if (header->data && std::string(header->data) != "Expect:") {
841 cmd << " \\\n -H '" << header->data << "'";
842 }
843 header = header->next;
844 }
845
846 // Form fields (multipart) - iterate through curl_httppost
847 ::curl_httppost *formpost = p->form;
848 while (formpost) {
849 if (formpost->showfilename) {
850 // File upload (showfilename is set when CURLFORM_FILENAME is used)
851 cmd << " \\\n -F '" << formpost->name << "=@" << formpost->showfilename << "'";
852 } else if (formpost->contents) {
853 // Regular form field with contents
854 cmd << " \\\n -F '" << formpost->name << "=" << formpost->contents << "'";
855 } else {
856 // Stream or other type without direct contents
857 cmd << " \\\n -F '" << formpost->name << "=<data>'";
858 }
859 formpost = formpost->next;
860 }
861
862 // Post body
863 if (!p->postfields.empty()) {
864 // Escape single quotes in the body for shell safety
865 std::string escaped_body = p->postfields;
866 size_t pos = 0;
867 while ((pos = escaped_body.find('\'', pos)) != std::string::npos) {
868 escaped_body.replace(pos, 1, "'\\''");
869 pos += 4;
870 }
871 // Truncate if too long for display
872 if (escaped_body.length() > 1000) {
873 escaped_body = escaped_body.substr(0, 1000) + "...<truncated>";
874 }
875 cmd << " \\\n -d '" << escaped_body << "'";
876 }
877
878 // Put file
879 if (p->putFile) {
880 cmd << " \\\n --upload-file <file-stream>";
881 }
882
883 BOOST_LOG_TRIVIAL(info) << "Http request:\n" << cmd.str();
884}
Vec3d pos(const Pt &p)
Definition ReprojectPointsOnMesh.hpp:16

References header(), and p.

Here is the call graph for this function:

◆ put()

Http Slic3r::Http::put ( std::string url)
static
900{
901 Http http{std::move(url)};
902 http.p->method = "PUT";
903 curl_easy_setopt(http.p->curl, CURLOPT_UPLOAD, 1L);
904 return http;
905}

References Http(), and Slic3r::http.

Referenced by Slic3r::OrcaCloudServiceAgent::http_put(), Slic3r::PrusaLink::put_inner(), Slic3r::Duet::upload(), and Slic3r::UltiMaker::upload().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ put2()

Http Slic3r::Http::put2 ( std::string url)
static
908{
909 Http http{ std::move(url) };
910 http.p->method = "PUT";
911 curl_easy_setopt(http.p->curl, CURLOPT_CUSTOMREQUEST, "PUT");
912 return http;
913}

References Http(), and Slic3r::http.

Referenced by Slic3r::ElegooLink::loopUploadCC2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_header()

Http & Slic3r::Http::remove_header ( std::string name)
617{
618 if (p) {
619 name.push_back(':');
620 p->headerlist = curl_slist_append(p->headerlist, name.c_str());
621 }
622
623 return *this;
624}

References Http(), and p.

Here is the call graph for this function:

◆ set_del_body()

Http & Slic3r::Http::set_del_body ( const std::string & body)
759{
760 if (p) { p->set_del_body(body); }
761 return *this;
762}

References Http(), and p.

Here is the call graph for this function:

◆ set_extra_headers()

void Slic3r::Http::set_extra_headers ( std::map< std::string, std::string > headers)
static
932{
933 std::lock_guard<std::mutex> l(g_mutex);
934 extra_headers.swap(headers);
935}

References Slic3r::extra_headers, and Slic3r::g_mutex.

Referenced by Slic3r::PresetUpdater::priv::sync_plugins().

Here is the caller graph for this function:

◆ set_post_body() [1/2]

Http & Slic3r::Http::set_post_body ( const boost::filesystem::path & path)

References Http().

Here is the call graph for this function:

◆ set_post_body() [2/2]

Http & Slic3r::Http::set_post_body ( const std::string & body)
747{
748 if (p) { p->set_post_body(body); }
749 return *this;
750}

References Http(), and p.

Here is the call graph for this function:

◆ set_put_body()

Http & Slic3r::Http::set_put_body ( const boost::filesystem::path & path)
753{
754 if (p) { p->set_put_body(path);}
755 return *this;
756}

References Http(), and p.

Here is the call graph for this function:

◆ set_range()

Http & Slic3r::Http::set_range ( const std::string & range)
583{
584 if (p) { p->set_range(range); }
585 return *this;
586}
auto range(Cont &&cont)
Definition libslic3r.h:405

References Http(), p, and Slic3r::range().

Referenced by Slic3r::GUI::FileGet::priv::get_perform().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ size_limit()

Http & Slic3r::Http::size_limit ( size_t sizeLimit)
577{
578 if (p) { p->limit = sizeLimit; }
579 return *this;
580}

References Http(), and p.

Referenced by Slic3r::GUI::FileGet::priv::get_perform(), and Slic3r::PresetUpdater::priv::sync_version().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timeout_connect()

Http & Slic3r::Http::timeout_connect ( long timeout)
563{
564 if (timeout < 1) { timeout = priv::DEFAULT_TIMEOUT_CONNECT; }
565 if (p) { p->set_timeout_connect(timeout); }
566 return *this;
567}
@ DEFAULT_TIMEOUT_CONNECT
Definition Http.cpp:123

References Http(), Slic3r::Http::priv::DEFAULT_TIMEOUT_CONNECT, and p.

Referenced by Slic3r::PresetUpdater::priv::check_new_vendors(), Slic3r::GUI::GUI_App::download_plugin(), and Slic3r::PresetUpdater::priv::sync_vendor_config().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timeout_max()

Http & Slic3r::Http::timeout_max ( long timeout)
570{
571 if (timeout < 1) { timeout = priv::DEFAULT_TIMEOUT_MAX; }
572 if (p) { p->set_timeout_max(timeout); }
573 return *this;
574}
@ DEFAULT_TIMEOUT_MAX
Definition Http.cpp:124

References Http(), Slic3r::Http::priv::DEFAULT_TIMEOUT_MAX, and p.

Referenced by Slic3r::GUI::GUI_App::download_plugin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tls_global_init()

std::string Slic3r::Http::tls_global_init ( )
static
952{
954 CurlGlobalInit::instance = std::make_unique<CurlGlobalInit>();
955
956 return CurlGlobalInit::instance->message;
957}
static std::unique_ptr< CurlGlobalInit > instance
Definition Http.cpp:46

References Slic3r::CurlGlobalInit::instance.

Referenced by Slic3r::Http::priv::priv(), and Slic3r::GUI::GUI_App::on_init_inner().

Here is the caller graph for this function:

◆ tls_system_cert_store()

std::string Slic3r::Http::tls_system_cert_store ( )
static
960{
961#ifdef OPENSSL_CERT_OVERRIDE
962 if (const char *cert_file = ::getenv(X509_get_default_cert_file_env()))
963 return cert_file;
964#endif
965
966 return {};
967}

Referenced by Slic3r::GUI::GUI_App::on_init_inner().

Here is the caller graph for this function:

◆ tls_verify()

Http & Slic3r::Http::tls_verify ( bool enable)
655{
656 if (p) {
657 ::curl_easy_setopt(p->curl, CURLOPT_SSL_VERIFYPEER, enable ? 1L : 0L);
658 ::curl_easy_setopt(p->curl, CURLOPT_SSL_VERIFYHOST, enable ? 2L : 0L);
659 ::curl_easy_setopt(p->curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
660 }
661 return *this;
662}
#define L(s)
Definition ExtrusionEntity.cpp:25

References Http(), L, and p.

Here is the call graph for this function:

◆ url_decode()

std::string Slic3r::Http::url_decode ( const std::string & str)
static
985{
986 ::CURL *curl = ::curl_easy_init();
987 if (curl == nullptr) { return str; }
988 int outlen = 0;
989 char *ce = ::curl_easy_unescape(curl, str.c_str(), str.length(), &outlen);
990 std::string dencoded = std::string(ce, outlen);
991
992 ::curl_free(ce);
993 ::curl_easy_cleanup(curl);
994
995 return dencoded;
996}

Referenced by Slic3r::GUI::session::read_next_line(), and Slic3r::GUI::GUI_App::url_decode().

Here is the caller graph for this function:

◆ url_encode()

std::string Slic3r::Http::url_encode ( const std::string & str)
static

Member Data Documentation

◆ p


The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Utils/Http.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Utils/Http.cpp