OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::session Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/HttpServer.hpp>

Inheritance diagram for Slic3r::GUI::session:
Collaboration diagram for Slic3r::GUI::session:

Public Member Functions

 session (HttpServer::IOServer &server, boost::asio::ip::tcp::socket socket)
void start ()
void stop ()

Private Member Functions

void read_first_line ()
void read_next_line ()
void read_body ()

Private Attributes

HttpServer::IOServer & server
boost::asio::ip::tcp::socket socket
boost::asio::streambuf buff
http_headers headers

Detailed Description

Constructor & Destructor Documentation

◆ session()

Slic3r::GUI::session::session ( HttpServer::IOServer & server,
boost::asio::ip::tcp::socket socket )
inline
172: server(server), socket(std::move(socket)) {}
HttpServer::IOServer & server
Definition HttpServer.hpp:161
boost::asio::ip::tcp::socket socket
Definition HttpServer.hpp:162

References server, and socket.

Member Function Documentation

◆ read_body()

void Slic3r::GUI::session::read_body ( )
private
82{
83 auto self(shared_from_this());
84
85 int nbuffer = 1000;
86 std::shared_ptr<std::vector<char>> bufptr = std::make_shared<std::vector<char>>(nbuffer);
87 async_read(socket, boost::asio::buffer(*bufptr, nbuffer),
88 [this, self, bufptr](const boost::beast::error_code& e, std::size_t s) { server.stop(self); });
89}

References server, and socket.

Referenced by read_next_line().

Here is the caller graph for this function:

◆ read_first_line()

void Slic3r::GUI::session::read_first_line ( )
private
64{
65 auto self(shared_from_this());
66
67 async_read_until(socket, buff, '\r', [this, self](const boost::beast::error_code& e, std::size_t s) {
68 if (!e) {
69 std::string line, ignore;
70 std::istream stream{&buff};
71 std::getline(stream, line, '\r');
72 std::getline(stream, ignore, '\n');
73 headers.on_read_request_line(line);
75 } else if (e != boost::asio::error::operation_aborted) {
76 server.stop(self);
77 }
78 });
79}
boost::asio::streambuf buff
Definition HttpServer.hpp:164
http_headers headers
Definition HttpServer.hpp:165
void read_next_line()
Definition HttpServer.cpp:91

References buff, headers, read_next_line(), server, and socket.

Referenced by start().

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

◆ read_next_line()

void Slic3r::GUI::session::read_next_line ( )
private
92{
93 auto self(shared_from_this());
94
95 async_read_until(socket, buff, '\r', [this, self](const boost::beast::error_code& e, std::size_t s) {
96 if (!e) {
97 std::string line, ignore;
98 std::istream stream{&buff};
99 std::getline(stream, line, '\r');
100 std::getline(stream, ignore, '\n');
101 headers.on_read_header(line);
102
103 if (line.length() == 0) {
104 if (headers.content_length() == 0) {
105 std::cout << "Request received: " << headers.method << " " << headers.get_url();
106 if (headers.method == "OPTIONS") {
107 // Ignore http OPTIONS
108 server.stop(self);
109 return;
110 }
111
112 const std::string url_str = Http::url_decode(headers.get_url());
113 const auto resp = server.server.m_request_handler(url_str);
114 std::stringstream ssOut;
115 resp->write_response(ssOut);
116 std::shared_ptr<std::string> str = std::make_shared<std::string>(ssOut.str());
117 async_write(socket, boost::asio::buffer(str->c_str(), str->length()),
118 [this, self, str](const boost::beast::error_code& e, std::size_t s) {
119 std::cout << "done" << std::endl;
120 server.stop(self);
121 });
122 } else {
123 read_body();
124 }
125 } else {
127 }
128 } else if (e != boost::asio::error::operation_aborted) {
129 server.stop(self);
130 }
131 });
132}
void read_body()
Definition HttpServer.cpp:81
static std::string url_decode(const std::string &str)
Definition Http.cpp:984

References buff, headers, read_body(), read_next_line(), server, socket, and Slic3r::Http::url_decode().

Referenced by read_first_line(), and read_next_line().

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

◆ start()

void Slic3r::GUI::session::start ( )
52{
54}
void read_first_line()
Definition HttpServer.cpp:63

References read_first_line().

Here is the call graph for this function:

◆ stop()

void Slic3r::GUI::session::stop ( )
57{
58 boost::system::error_code ignored_ec;
59 socket.shutdown(boost::asio::socket_base::shutdown_both, ignored_ec);
60 socket.close(ignored_ec);
61}

References socket.

Member Data Documentation

◆ buff

boost::asio::streambuf Slic3r::GUI::session::buff
private

Referenced by read_first_line(), and read_next_line().

◆ headers

http_headers Slic3r::GUI::session::headers
private

Referenced by read_first_line(), and read_next_line().

◆ server

HttpServer::IOServer& Slic3r::GUI::session::server
private

◆ socket

boost::asio::ip::tcp::socket Slic3r::GUI::session::socket
private

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