Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::Http Class Reference

Represetns a Http request. More...

#include <src/slic3r/Utils/Http.hpp>

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

Classes

struct  priv
 
struct  Progress
 

Public Types

typedef std::shared_ptr< HttpPtr
 
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
 

Public Member Functions

 Http (Http &&other)
 
 ~Http ()
 
 Http (const Http &)=delete
 
Httpoperator= (const Http &)=delete
 
Httpoperator= (Http &&)=delete
 
Httptimeout_connect (long timeout)
 
Httptimeout_max (long timeout)
 
Httpsize_limit (size_t sizeLimit)
 
Httpset_range (const std::string &range)
 
Httpheader (std::string name, const std::string &value)
 
Httpremove_header (std::string name)
 
Httpauth_digest (const std::string &user, const std::string &password)
 
Httpauth_basic (const std::string &user, const std::string &password)
 
Httpca_file (const std::string &filename)
 
Httpform_add (const std::string &name, const std::string &contents)
 
Httpform_add_file (const std::string &name, const boost::filesystem::path &path)
 
Httpform_add_file (const std::string &name, const boost::filesystem::path &path, const std::string &filename)
 
Httpset_post_body (const boost::filesystem::path &path)
 
Httpset_post_body (const std::string &body)
 
Httpset_put_body (const boost::filesystem::path &path)
 
Httpon_complete (CompleteFn fn)
 
Httpon_error (ErrorFn fn)
 
Httpon_progress (ProgressFn fn)
 
Httpon_ip_resolve (IPResolveFn fn)
 
Ptr perform ()
 
void perform_sync ()
 
void cancel ()
 

Static Public Member Functions

static Http get (std::string url)
 
static Http post (std::string url)
 
static Http put (std::string url)
 
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)
 

Private Member Functions

 Http (const std::string &url)
 

Private Attributes

std::unique_ptr< privp
 

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

◆ 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)
416: p(std::move(other.p)) {}
std::unique_ptr< priv > p
Definition Http.hpp:144

◆ ~Http()

Slic3r::Http::~Http ( )
419{
420 assert(! p || ! p->putFile);
421 if (p && p->io_thread.joinable()) {
422 p->io_thread.detach();
423 }
424}

References p.

◆ Http() [2/3]

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

◆ Http() [3/3]

Slic3r::Http::Http ( const std::string &  url)
private
411: p(new priv(url)) {}
Definition CutSurface.cpp:39

Member Function Documentation

◆ auth_basic()

Http & Slic3r::Http::auth_basic ( const std::string &  user,
const std::string &  password 
)
487{
488 curl_easy_setopt(p->curl, CURLOPT_USERNAME, user.c_str());
489 curl_easy_setopt(p->curl, CURLOPT_PASSWORD, password.c_str());
490 curl_easy_setopt(p->curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
491
492 return *this;
493}

References p.

◆ auth_digest()

Http & Slic3r::Http::auth_digest ( const std::string &  user,
const std::string &  password 
)
478{
479 curl_easy_setopt(p->curl, CURLOPT_USERNAME, user.c_str());
480 curl_easy_setopt(p->curl, CURLOPT_PASSWORD, password.c_str());
481 curl_easy_setopt(p->curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
482
483 return *this;
484}

References p.

Referenced by Slic3r::PrusaLink::set_auth().

+ Here is the caller graph for this function:

◆ ca_file()

Http & Slic3r::Http::ca_file ( const std::string &  filename)
496{
497 if (p && priv::ca_file_supported(p->curl)) {
498 ::curl_easy_setopt(p->curl, CURLOPT_CAINFO, name.c_str());
499 }
500
501 return *this;
502}
static bool ca_file_supported(::CURL *curl)
Definition Http.cpp:183

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

Referenced by Slic3r::AstroBox::set_auth(), Slic3r::Moonraker::set_auth(), Slic3r::OctoPrint::set_auth(), Slic3r::Repetier::set_auth(), and Slic3r::PrusaLink::set_auth().

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

◆ ca_file_supported()

bool Slic3r::Http::ca_file_supported ( )
static
627{
628 ::CURL *curl = ::curl_easy_init();
629 bool res = priv::ca_file_supported(curl);
630 if (curl != nullptr) { ::curl_easy_cleanup(curl); }
631 return res;
632}

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

Referenced by Slic3r::GUI::PhysicalPrinterDialog::build_printhost_settings().

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

◆ cancel()

void Slic3r::Http::cancel ( )
603{
604 if (p) { p->cancel = true; }
605}

References p.

Referenced by Slic3r::Http::priv::http_perform().

+ Here is the caller graph for this function:

◆ form_add()

Http & Slic3r::Http::form_add ( const std::string &  name,
const std::string &  contents 
)
505{
506 if (p) {
507 ::curl_formadd(&p->form, &p->form_end,
508 CURLFORM_COPYNAME, name.c_str(),
509 CURLFORM_COPYCONTENTS, contents.c_str(),
510 CURLFORM_END
511 );
512 }
513
514 return *this;
515}

References p.

Referenced by Slic3r::PrusaLink::post_inner(), Slic3r::PrusaLink::set_http_post_header_args(), and Slic3r::PrusaConnect::set_http_post_header_args().

+ Here is the caller graph for this function:

◆ form_add_file() [1/2]

Http & Slic3r::Http::form_add_file ( const std::string &  name,
const boost::filesystem::path &  path 
)

Referenced by Slic3r::PrusaLink::post_inner().

+ Here is the caller graph for this function:

◆ form_add_file() [2/2]

Http & Slic3r::Http::form_add_file ( const std::string &  name,
const boost::filesystem::path &  path,
const std::string &  filename 
)

◆ get()

◆ header()

Http & Slic3r::Http::header ( std::string  name,
const std::string &  value 
)
454{
455 if (!p) { return * this; }
456
457 if (name.size() > 0) {
458 name.append(": ").append(value);
459 } else {
460 name.push_back(':');
461 }
462 p->headerlist = curl_slist_append(p->headerlist, name.c_str());
463 return *this;
464}

References p.

Referenced by Slic3r::PrusaLink::post_inner(), Slic3r::PrusaLink::put_inner(), Slic3r::GUI::SendSystemInfoDialog::send_info(), Slic3r::AstroBox::set_auth(), Slic3r::Moonraker::set_auth(), Slic3r::OctoPrint::set_auth(), Slic3r::Repetier::set_auth(), Slic3r::PrusaLink::set_auth(), and Slic3r::PrusaConnect::set_http_post_header_args().

+ Here is the caller graph for this function:

◆ on_complete()

Http & Slic3r::Http::on_complete ( CompleteFn  fn)
560{
561 if (p) { p->completefn = std::move(fn); }
562 return *this;
563}

References p.

Referenced by Slic3r::PrusaLink::post_inner(), Slic3r::PrusaLink::put_inner(), and Slic3r::GUI::SendSystemInfoDialog::send_info().

+ Here is the caller graph for this function:

◆ on_error()

Http & Slic3r::Http::on_error ( ErrorFn  fn)
566{
567 if (p) { p->errorfn = std::move(fn); }
568 return *this;
569}

References p.

◆ on_ip_resolve()

Http & Slic3r::Http::on_ip_resolve ( IPResolveFn  fn)
578{
579 if (p) { p->ipresolvefn = std::move(fn); }
580 return *this;
581}

References p.

◆ on_progress()

Http & Slic3r::Http::on_progress ( ProgressFn  fn)
572{
573 if (p) { p->progressfn = std::move(fn); }
574 return *this;
575}

References p.

Referenced by Slic3r::PresetUpdater::priv::get_file(), Slic3r::GUI::FileGet::priv::get_perform(), and Slic3r::AppUpdater::priv::http_get_file().

+ Here is the caller graph for this function:

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ perform()

Http::Ptr Slic3r::Http::perform ( )
584{
585 auto self = std::make_shared<Http>(std::move(*this));
586
587 if (self->p) {
588 auto io_thread = std::thread([self](){
589 self->p->http_perform();
590 });
591 self->p->io_thread = std::move(io_thread);
592 }
593
594 return self;
595}

◆ perform_sync()

void Slic3r::Http::perform_sync ( )
598{
599 if (p) { p->http_perform(); }
600}

References p.

Referenced by Slic3r::PrusaLink::post_inner(), and Slic3r::PrusaLink::put_inner().

+ Here is the caller graph for this function:

◆ post()

Http Slic3r::Http::post ( std::string  url)
static
613{
614 Http http{std::move(url)};
615 curl_easy_setopt(http.p->curl, CURLOPT_POST, 1L);
616 return http;
617}

Referenced by Slic3r::PrusaLink::post_inner(), Slic3r::GUI::SendSystemInfoDialog::send_info(), Slic3r::Duet::start_print(), Slic3r::AstroBox::upload(), Slic3r::Duet::upload(), Slic3r::FlashAir::upload(), Slic3r::MKS::upload(), Slic3r::Moonraker::upload(), Slic3r::Repetier::upload(), and Slic3r::OctoPrint::upload_inner_with_host().

+ Here is the caller graph for this function:

◆ put()

Http Slic3r::Http::put ( std::string  url)
static
620{
621 Http http{std::move(url)};
622 curl_easy_setopt(http.p->curl, CURLOPT_UPLOAD, 1L);
623 return http;
624}

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

+ Here is the caller graph for this function:

◆ remove_header()

Http & Slic3r::Http::remove_header ( std::string  name)
467{
468 if (p) {
469 name.push_back(':');
470 p->headerlist = curl_slist_append(p->headerlist, name.c_str());
471 }
472
473 return *this;
474}

References p.

◆ set_post_body() [1/2]

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

Referenced by Slic3r::GUI::SendSystemInfoDialog::send_info().

+ Here is the caller graph for this function:

◆ set_post_body() [2/2]

Http & Slic3r::Http::set_post_body ( const std::string &  body)
548{
549 if (p) { p->set_post_body(body); }
550 return *this;
551}

References p.

◆ set_put_body()

Http & Slic3r::Http::set_put_body ( const boost::filesystem::path &  path)
554{
555 if (p) { p->set_put_body(path);}
556 return *this;
557}

References p.

Referenced by Slic3r::PrusaLink::put_inner().

+ Here is the caller graph for this function:

◆ set_range()

Http & Slic3r::Http::set_range ( const std::string &  range)
448{
449 if (p) { p->set_range(range); }
450 return *this;
451}
auto range(Cont &&cont)
Definition libslic3r.h:356

References 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)
442{
443 if (p) { p->limit = sizeLimit; }
444 return *this;
445}

References p.

Referenced by Slic3r::GUI::FileGet::priv::get_perform(), and Slic3r::AppUpdater::priv::http_get_file().

+ Here is the caller graph for this function:

◆ timeout_connect()

Http & Slic3r::Http::timeout_connect ( long  timeout)
428{
429 if (timeout < 1) { timeout = priv::DEFAULT_TIMEOUT_CONNECT; }
430 if (p) { p->set_timeout_connect(timeout); }
431 return *this;
432}
@ DEFAULT_TIMEOUT_CONNECT
Definition Http.cpp:106

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

◆ timeout_max()

Http & Slic3r::Http::timeout_max ( long  timeout)
435{
436 if (timeout < 1) { timeout = priv::DEFAULT_TIMEOUT_MAX; }
437 if (p) { p->set_timeout_max(timeout); }
438 return *this;
439}
@ DEFAULT_TIMEOUT_MAX
Definition Http.cpp:107

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

Referenced by Slic3r::GUI::SendSystemInfoDialog::send_info().

+ Here is the caller graph for this function:

◆ tls_global_init()

std::string Slic3r::Http::tls_global_init ( )
static
635{
637 CurlGlobalInit::instance = std::make_unique<CurlGlobalInit>();
638
639 return CurlGlobalInit::instance->message;
640}
static std::unique_ptr< CurlGlobalInit > instance
Definition Http.cpp:36

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
643{
644 std::string ret;
645
646#ifdef OPENSSL_CERT_OVERRIDE
647 ret = ::getenv(X509_get_default_cert_file_env());
648#endif
649
650 return ret;
651}
char * getenv()

References getenv().

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

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

◆ url_encode()

std::string Slic3r::Http::url_encode ( const std::string &  str)
static
654{
655 ::CURL *curl = ::curl_easy_init();
656 if (curl == nullptr) {
657 return str;
658 }
659 char *ce = ::curl_easy_escape(curl, str.c_str(), str.length());
660 std::string encoded = std::string(ce);
661
662 ::curl_free(ce);
663 ::curl_easy_cleanup(curl);
664
665 return encoded;
666}

Referenced by Slic3r::MKS::get_upload_url(), Slic3r::Duet::get_upload_url(), and Slic3r::Duet::start_print().

+ Here is the caller graph for this function:

Member Data Documentation

◆ p


The documentation for this class was generated from the following files: