* Initial commit for the builder * fix wx, use hack to install into /app * add some workarounds for /usr/local * fix up rest of paths * attempt to fix wxwebview undef * figure out why wxwidgets isnt getting its patches applied * do "proper" patching of wxwidgets * Flip the flag * actually append the /usr/local * restrict package finding to flatpak only * Update the destdir stuff for mpfr, gmp * Transfer over all the _destdir, again * update patch command for all other plats * initial ci check * what even happened * clear ci image * I doubt this will do anything * do cleanup after running each step * remove build objects for flatpak ci * compress debug info * Fix MacOS build * Try saving space after building deps * No debug info for now * Do debug info, use thin static archives * use BSD flag, not --thin * try building with lto * Use release, no debug info * remove lto * Revert the last 5 commits * It might require write perms * Revert "It might require write perms" This reverts commit 44cec58a5713cb5ebbc44e64e314b88b553b8f75. * Import fixes for merge * remove some patch stuff * the worst hack! * remove uneeded patches * Initial commit for the builder * note to self, go back to regular wx * attempt to fix wxwebview undef * do "proper" patching of wxwidgets * update patch command for all other plats * what even happened * -ldep_name-NOTFOUND is still here * concat patches * Build wx with flatpak * more wx shenatigans * fix a missing import * build wx with proper flags * fix imports and libs * trigger ci * try fixing mac and windows ci * remove duplicate definition of freetype * curl may not have openssl for a dep * has openssl been found? * force building * build images on apple * cleanup for review * cleanup cmake files --------- Co-authored-by: SoftFever <softfeverever@gmail.com>
161 lines
4.0 KiB
C++
161 lines
4.0 KiB
C++
#ifndef slic3r_Http_App_hpp_
|
|
#define slic3r_Http_App_hpp_
|
|
|
|
#include <iostream>
|
|
#include <mutex>
|
|
#include <stack>
|
|
|
|
#include <boost/beast/core.hpp>
|
|
#include <boost/beast/http.hpp>
|
|
#include <boost/beast/version.hpp>
|
|
#include <boost/asio.hpp>
|
|
#include <boost/thread.hpp>
|
|
#include <string>
|
|
#include <set>
|
|
#include <memory>
|
|
|
|
#define LOCALHOST_PORT 13618
|
|
#define LOCALHOST_URL "http://localhost:"
|
|
|
|
namespace Slic3r { namespace GUI {
|
|
|
|
class session;
|
|
|
|
class http_headers
|
|
{
|
|
std::string method;
|
|
std::string url;
|
|
std::string version;
|
|
|
|
std::map<std::string, std::string> headers;
|
|
|
|
friend class session;
|
|
public:
|
|
std::string get_url() { return url; }
|
|
|
|
int content_length()
|
|
{
|
|
auto request = headers.find("content-length");
|
|
if (request != headers.end()) {
|
|
std::stringstream ssLength(request->second);
|
|
int content_length;
|
|
ssLength >> content_length;
|
|
return content_length;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void on_read_header(std::string line)
|
|
{
|
|
// std::cout << "header: " << line << std::endl;
|
|
|
|
std::stringstream ssHeader(line);
|
|
std::string headerName;
|
|
std::getline(ssHeader, headerName, ':');
|
|
|
|
std::string value;
|
|
std::getline(ssHeader, value);
|
|
headers[headerName] = value;
|
|
}
|
|
|
|
void on_read_request_line(std::string line)
|
|
{
|
|
std::stringstream ssRequestLine(line);
|
|
ssRequestLine >> method;
|
|
ssRequestLine >> url;
|
|
ssRequestLine >> version;
|
|
|
|
std::cout << "request for resource: " << url << std::endl;
|
|
}
|
|
};
|
|
|
|
class HttpServer
|
|
{
|
|
boost::asio::ip::port_type port;
|
|
|
|
public:
|
|
class Response
|
|
{
|
|
public:
|
|
virtual ~Response() = default;
|
|
virtual void write_response(std::stringstream& ssOut) = 0;
|
|
};
|
|
|
|
class ResponseNotFound : public Response
|
|
{
|
|
public:
|
|
~ResponseNotFound() override = default;
|
|
void write_response(std::stringstream& ssOut) override;
|
|
};
|
|
|
|
class ResponseRedirect : public Response
|
|
{
|
|
const std::string location_str;
|
|
|
|
public:
|
|
ResponseRedirect(const std::string& location) : location_str(location) {}
|
|
~ResponseRedirect() override = default;
|
|
void write_response(std::stringstream& ssOut) override;
|
|
};
|
|
|
|
HttpServer(boost::asio::ip::port_type port = LOCALHOST_PORT);
|
|
|
|
boost::thread m_http_server_thread;
|
|
bool start_http_server = false;
|
|
|
|
bool is_started() { return start_http_server; }
|
|
void start();
|
|
void stop();
|
|
void set_request_handler(const std::function<std::shared_ptr<Response>(const std::string&)>& m_request_handler);
|
|
|
|
static std::shared_ptr<Response> bbl_auth_handle_request(const std::string& url);
|
|
|
|
private:
|
|
class IOServer
|
|
{
|
|
public:
|
|
HttpServer& server;
|
|
boost::asio::io_service io_service;
|
|
boost::asio::ip::tcp::acceptor acceptor;
|
|
std::set<std::shared_ptr<session>> sessions;
|
|
|
|
IOServer(HttpServer& server) : server(server), acceptor(io_service, {boost::asio::ip::tcp::v4(), server.port}) {}
|
|
|
|
void do_accept();
|
|
|
|
void start(std::shared_ptr<session> session);
|
|
void stop(std::shared_ptr<session> session);
|
|
void stop_all();
|
|
};
|
|
friend class session;
|
|
|
|
std::unique_ptr<IOServer> server_{nullptr};
|
|
|
|
std::function<std::shared_ptr<Response>(const std::string&)> m_request_handler{&HttpServer::bbl_auth_handle_request};
|
|
};
|
|
|
|
class session : public std::enable_shared_from_this<session>
|
|
{
|
|
HttpServer::IOServer& server;
|
|
boost::asio::ip::tcp::socket socket;
|
|
|
|
boost::asio::streambuf buff;
|
|
http_headers headers;
|
|
|
|
void read_first_line();
|
|
void read_next_line();
|
|
void read_body();
|
|
|
|
public:
|
|
session(HttpServer::IOServer& server, boost::asio::ip::tcp::socket socket) : server(server), socket(std::move(socket)) {}
|
|
|
|
void start();
|
|
void stop();
|
|
};
|
|
|
|
std::string url_get_param(const std::string& url, const std::string& key);
|
|
|
|
}};
|
|
|
|
#endif
|