SNode.C
|
#include <Request.h>
Public Member Functions | |
Request (web::http::client::SocketContext *socketContext, const std::string &host) | |
Request (Request &)=delete | |
Request (Request &&) noexcept | |
Request & | operator= (Request &)=delete |
Request & | operator= (Request &&) noexcept=delete |
~Request () override | |
void | setMasterRequest (const std::shared_ptr< Request > &masterRequest) |
virtual void | init () |
Request & | host (const std::string &hostFieldValue) |
Request & | append (const std::string &field, const std::string &value) |
Request & | set (const std::string &field, const std::string &value, bool overwrite=true) |
Request & | set (const std::map< std::string, std::string > &headers, bool overwrite=true) |
Request & | type (const std::string &type) |
Request & | cookie (const std::string &name, const std::string &value) |
Request & | cookie (const std::map< std::string, std::string > &cookies) |
Request & | query (const std::string &key, const std::string &value) |
Request & | setTrailer (const std::string &field, const std::string &value, bool overwrite=true) |
bool | send (const char *chunk, std::size_t chunkLen, const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &onResponseReceived, const std::function< void(const std::shared_ptr< Request > &, const std::string &)> &onResponseParseError=responseParseError) |
bool | send (const std::string &chunk, const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &onResponseReceived, const std::function< void(const std::shared_ptr< Request > &, const std::string &)> &onResponseParseError=responseParseError) |
bool | upgrade (const std::string &url, const std::string &protocols, const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &onResponseReceived, const std::function< void(const std::shared_ptr< Request > &, const std::string &)> &onResponseParseError=responseParseError) |
void | upgrade (const std::shared_ptr< Response > &response, const std::function< void(const std::string &)> &status) |
bool | sendFile (const std::string &file, const std::function< void(int errnum)> &onStatus, const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &onResponseReceived, const std::function< void(const std::shared_ptr< Request > &, const std::string &)> &onResponseParseError=responseParseError) |
Request & | sendHeader () |
Request & | sendFragment (const char *chunk, std::size_t chunkLen) |
Request & | sendFragment (const std::string &data) |
bool | end (const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &onResponseReceived, const std::function< void(const std::shared_ptr< Request > &, const std::string &)> &onResponseParseError=responseParseError) |
std::string | header (const std::string &field) |
const CiStringMap< std::string > & | getQueries () const |
const CiStringMap< std::string > & | getHeaders () const |
const CiStringMap< std::string > & | getCookies () const |
web::http::client::SocketContext * | getSocketContext () const |
![]() | |
Sink (Sink &)=delete | |
Sink & | operator= (Sink &)=delete |
Static Public Member Functions | |
static void | responseParseError (const std::shared_ptr< Request > &request, const std::string &message) |
Public Attributes | |
std::string | hostFieldValue |
std::string | method = "GET" |
std::string | url = "/" |
int | httpMajor = 1 |
int | httpMinor = 1 |
Protected Attributes | |
CiStringMap< std::string > | queries |
CiStringMap< std::string > | headers |
CiStringMap< std::string > | cookies |
CiStringMap< std::string > | trailer |
Private Member Functions | |
bool | initiate () |
bool | executeSendFile (const std::string &file, const std::function< void(int)> &onStatus) |
bool | executeUpgrade (const std::string &url, const std::string &protocols) |
bool | executeEnd () |
bool | executeSendHeader () |
bool | executeSendFragment (const char *chunk, std::size_t chunkLen) |
void | requestPrepared () |
void | requestDelivered () |
void | deliverResponse (const std::shared_ptr< Request > &request, const std::shared_ptr< Response > &response) |
void | deliverResponseParseError (const std::shared_ptr< Request > &request, const std::string &message) |
void | onSourceConnect (core::pipe::Source *source) override |
void | onSourceData (const char *chunk, std::size_t chunkLen) override |
void | onSourceEof () override |
void | onSourceError (int errnum) override |
Private Attributes | |
std::list< RequestCommand * > | requestCommands |
TransferEncoding | transferEncoding = TransferEncoding::HTTP10 |
std::size_t | contentLength = 0 |
std::size_t | contentLengthSent = 0 |
ConnectionState | connectionState = ConnectionState::Default |
std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> | onResponseReceived |
std::function< void(const std::shared_ptr< Request > &request, const std::string &message)> | onResponseParseError |
std::weak_ptr< Request > | masterRequest |
web::http::client::SocketContext * | socketContext |
Friends | |
class | commands::SendFileCommand |
class | commands::SendFragmentCommand |
class | commands::SendHeaderCommand |
class | commands::UpgradeCommand |
class | commands::EndCommand |
class | SocketContext |
Additional Inherited Members | |
![]() | |
Sink ()=default | |
Sink (Sink &&) noexcept=default | |
Sink & | operator= (Sink &&) noexcept=default |
virtual | ~Sink () |
bool | isStreaming () |
void | stop () |
|
explicit |
Definition at line 75 of file Request.cpp.
References host(), hostFieldValue, and socketContext.
|
explicitdelete |
|
explicitnoexcept |
Definition at line 81 of file Request.cpp.
References connectionState, contentLength, contentLengthSent, cookies, headers, hostFieldValue, httpMajor, httpMinor, init(), masterRequest, method, onResponseParseError, onResponseReceived, queries, requestCommands, socketContext, trailer, transferEncoding, and url.
|
override |
Definition at line 103 of file Request.cpp.
References core::pipe::Sink::isStreaming(), masterRequest, requestCommands, socketContext, and core::socket::stream::SocketContext::streamEof().
Request & web::http::client::Request::append | ( | const std::string & | field, |
const std::string & | value | ||
) |
Definition at line 147 of file Request.cpp.
References headers, and set().
Request & web::http::client::Request::cookie | ( | const std::map< std::string, std::string > & | cookies | ) |
Definition at line 225 of file Request.cpp.
References cookie().
Request & web::http::client::Request::cookie | ( | const std::string & | name, |
const std::string & | value | ||
) |
Definition at line 219 of file Request.cpp.
References cookies.
Referenced by cookie().
|
private |
Definition at line 580 of file Request.cpp.
References onResponseReceived.
Referenced by web::http::client::SocketContext::deliverResponse().
|
private |
Definition at line 584 of file Request.cpp.
References onResponseParseError.
Referenced by web::http::client::SocketContext::deliverResponseParseError().
bool web::http::client::Request::end | ( | const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> & | onResponseReceived, |
const std::function< void(const std::shared_ptr< Request > &, const std::string &)> & | onResponseParseError = responseParseError |
||
) |
Definition at line 416 of file Request.cpp.
References web::http::client::commands::EndCommand::EndCommand(), masterRequest, onResponseParseError, onResponseReceived, requestCommands, requestPrepared(), and sendHeader().
|
private |
Definition at line 523 of file Request.cpp.
Referenced by web::http::client::commands::EndCommand::execute().
|
private |
Definition at line 461 of file Request.cpp.
References contentLength, web::http::MimeTypes::contentType(), executeSendHeader(), httputils::file_mod_http_date(), httpMajor, httpMinor, core::file::FileReader::open(), core::pipe::Source::pipe(), and set().
Referenced by web::http::client::commands::SendFileCommand::execute().
|
private |
Definition at line 559 of file Request.cpp.
References web::http::Chunked, contentLength, contentLengthSent, core::socket::stream::SocketContext::sendToPeer(), core::socket::SocketContext::sendToPeer(), socketContext, and transferEncoding.
Referenced by web::http::client::commands::SendFragmentCommand::execute(), onSourceData(), and requestDelivered().
|
private |
Definition at line 527 of file Request.cpp.
References contentLength, cookies, headers, httpMajor, httpMinor, method, queries, core::socket::SocketContext::sendToPeer(), set(), socketContext, httputils::to_http_date(), url, and httputils::url_encode().
Referenced by web::http::client::commands::SendHeaderCommand::execute(), executeSendFile(), and executeUpgrade().
|
private |
Definition at line 503 of file Request.cpp.
References web::http::client::SocketContextUpgradeFactory::checkRefCount(), core::socket::stream::SocketContext::close(), executeSendHeader(), web::http::client::SocketContextUpgradeFactorySelector::instance(), web::http::client::SocketContextUpgradeFactorySelector::select(), set(), socketContext, and url.
Referenced by web::http::client::commands::UpgradeCommand::execute().
const web::http::CiStringMap< std::string > & web::http::client::Request::getCookies | ( | ) | const |
const web::http::CiStringMap< std::string > & web::http::client::Request::getHeaders | ( | ) | const |
const web::http::CiStringMap< std::string > & web::http::client::Request::getQueries | ( | ) | const |
SocketContext * web::http::client::Request::getSocketContext | ( | ) | const |
Definition at line 654 of file Request.cpp.
References socketContext.
Referenced by responseParseError().
std::string web::http::client::Request::header | ( | const std::string & | field | ) |
Definition at line 638 of file Request.cpp.
References headers.
Referenced by web::websocket::client::SocketContextUpgradeFactory::create(), main(), web::http::client::SocketContext::requestPrepared(), and upgrade().
Request & web::http::client::Request::host | ( | const std::string & | hostFieldValue | ) |
Definition at line 141 of file Request.cpp.
References set().
Referenced by init(), and Request().
|
virtual |
Definition at line 117 of file Request.cpp.
References connectionState, contentLength, contentLengthSent, cookies, web::http::Default, headers, host(), hostFieldValue, web::http::HTTP10, httpMajor, httpMinor, method, onResponseParseError, onResponseReceived, queries, requestCommands, set(), trailer, transferEncoding, and url.
Referenced by Request(), and requestPrepared().
|
private |
Definition at line 436 of file Request.cpp.
References contentLengthSent, web::http::client::RequestCommand::execute(), web::http::client::RequestCommand::getError(), requestCommands, and requestDelivered().
Referenced by web::http::client::SocketContext::initiateRequest().
|
overrideprivatevirtual |
Implements core::pipe::Sink.
Definition at line 605 of file Request.cpp.
References masterRequest, socketContext, core::pipe::Source::start(), core::pipe::Source::stop(), and core::socket::stream::SocketContext::streamToPeer().
|
overrideprivatevirtual |
Implements core::pipe::Sink.
Definition at line 615 of file Request.cpp.
References executeSendFragment().
|
overrideprivatevirtual |
Implements core::pipe::Sink.
Definition at line 619 of file Request.cpp.
References masterRequest, requestDelivered(), socketContext, and core::socket::stream::SocketContext::streamEof().
|
overrideprivatevirtual |
Implements core::pipe::Sink.
Definition at line 627 of file Request.cpp.
References core::socket::stream::SocketContext::close(), masterRequest, requestDelivered(), socketContext, and core::socket::stream::SocketContext::streamEof().
Request & web::http::client::Request::query | ( | const std::string & | key, |
const std::string & | value | ||
) |
Definition at line 233 of file Request.cpp.
References queries.
|
private |
Definition at line 588 of file Request.cpp.
References web::http::Chunked, contentLength, contentLengthSent, executeSendFragment(), masterRequest, web::http::client::SocketContext::requestDelivered(), core::socket::SocketContext::sendToPeer(), socketContext, trailer, and transferEncoding.
Referenced by initiate(), onSourceEof(), and onSourceError().
|
private |
Definition at line 575 of file Request.cpp.
References init(), web::http::client::SocketContext::requestPrepared(), and socketContext.
Referenced by end(), send(), sendFile(), and upgrade().
|
static |
Definition at line 258 of file Request.cpp.
References core::socket::stream::SocketConnection::getConnectionName(), core::socket::stream::SocketContext::getSocketConnection(), getSocketContext(), httpMajor, httpMinor, method, and url.
bool web::http::client::Request::send | ( | const char * | chunk, |
std::size_t | chunkLen, | ||
const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> & | onResponseReceived, | ||
const std::function< void(const std::shared_ptr< Request > &, const std::string &)> & | onResponseParseError = responseParseError |
||
) |
Definition at line 264 of file Request.cpp.
References web::http::client::commands::EndCommand::EndCommand(), masterRequest, onResponseParseError, onResponseReceived, requestCommands, requestPrepared(), sendFragment(), sendHeader(), and set().
Referenced by send().
bool web::http::client::Request::send | ( | const std::string & | chunk, |
const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> & | onResponseReceived, | ||
const std::function< void(const std::shared_ptr< Request > &, const std::string &)> & | onResponseParseError = responseParseError |
||
) |
Definition at line 291 of file Request.cpp.
Referenced by main().
bool web::http::client::Request::sendFile | ( | const std::string & | file, |
const std::function< void(int errnum)> & | onStatus, | ||
const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> & | onResponseReceived, | ||
const std::function< void(const std::shared_ptr< Request > &, const std::string &)> & | onResponseParseError = responseParseError |
||
) |
Definition at line 374 of file Request.cpp.
References masterRequest, onResponseParseError, onResponseReceived, requestCommands, requestPrepared(), and web::http::client::commands::SendFileCommand::SendFileCommand().
Request & web::http::client::Request::sendFragment | ( | const char * | chunk, |
std::size_t | chunkLen | ||
) |
Definition at line 402 of file Request.cpp.
References contentLength, masterRequest, requestCommands, and web::http::client::commands::SendFragmentCommand::SendFragmentCommand().
Referenced by send(), and sendFragment().
Request & web::http::client::Request::sendFragment | ( | const std::string & | data | ) |
Definition at line 412 of file Request.cpp.
References sendFragment().
Request & web::http::client::Request::sendHeader | ( | ) |
Definition at line 394 of file Request.cpp.
References masterRequest, requestCommands, and web::http::client::commands::SendHeaderCommand::SendHeaderCommand().
Referenced by end(), and send().
Request & web::http::client::Request::set | ( | const std::map< std::string, std::string > & | headers, |
bool | overwrite = true |
||
) |
Definition at line 205 of file Request.cpp.
References set().
Request & web::http::client::Request::set | ( | const std::string & | field, |
const std::string & | value, | ||
bool | overwrite = true |
||
) |
Definition at line 159 of file Request.cpp.
References web::http::Chunked, web::http::ciContains(), web::http::ciEquals(), web::http::Close, connectionState, contentLength, headers, web::http::Identity, web::http::Keep, and transferEncoding.
Referenced by append(), executeSendFile(), executeSendHeader(), executeUpgrade(), host(), init(), main(), web::websocket::client::SocketContextUpgradeFactory::prepare(), send(), send(), set(), and setTrailer().
void web::http::client::Request::setMasterRequest | ( | const std::shared_ptr< Request > & | masterRequest | ) |
Definition at line 113 of file Request.cpp.
References masterRequest.
Request & web::http::client::Request::setTrailer | ( | const std::string & | field, |
const std::string & | value, | ||
bool | overwrite = true |
||
) |
Definition at line 239 of file Request.cpp.
References headers, set(), and trailer.
Request & web::http::client::Request::type | ( | const std::string & | type | ) |
Definition at line 213 of file Request.cpp.
References headers.
Referenced by main().
void web::http::client::Request::upgrade | ( | const std::shared_ptr< Response > & | response, |
const std::function< void(const std::string &)> & | status | ||
) |
Definition at line 321 of file Request.cpp.
References web::http::ciContains(), core::socket::stream::SocketContext::close(), web::http::SocketContextUpgradeFactory< RequestT, ResponseT >::create(), web::http::client::Response::get(), core::socket::stream::SocketConnection::getConnectionName(), core::socket::stream::SocketContext::getSocketConnection(), header(), web::http::client::SocketContextUpgradeFactorySelector::instance(), masterRequest, web::http::SocketContextUpgradeFactory< RequestT, ResponseT >::name(), web::http::client::SocketContextUpgradeFactorySelector::select(), socketContext, and core::socket::stream::SocketContext::switchSocketContext().
Referenced by main().
bool web::http::client::Request::upgrade | ( | const std::string & | url, |
const std::string & | protocols, | ||
const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> & | onResponseReceived, | ||
const std::function< void(const std::shared_ptr< Request > &, const std::string &)> & | onResponseParseError = responseParseError |
||
) |
Definition at line 301 of file Request.cpp.
References masterRequest, onResponseParseError, onResponseReceived, requestCommands, requestPrepared(), and web::http::client::commands::UpgradeCommand::UpgradeCommand().
Referenced by main().
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
private |
|
private |
Definition at line 181 of file Request.h.
Referenced by executeSendFile(), executeSendFragment(), executeSendHeader(), init(), Request(), requestDelivered(), sendFragment(), and set().
|
private |
Definition at line 182 of file Request.h.
Referenced by executeSendFragment(), init(), initiate(), Request(), and requestDelivered().
|
protected |
Definition at line 173 of file Request.h.
Referenced by cookie(), executeSendHeader(), getCookies(), init(), and Request().
|
protected |
Definition at line 172 of file Request.h.
Referenced by append(), executeSendHeader(), getHeaders(), header(), init(), Request(), set(), setTrailer(), and type().
std::string web::http::client::Request::hostFieldValue |
int web::http::client::Request::httpMajor = 1 |
Definition at line 167 of file Request.h.
Referenced by web::http::client::SocketContext::deliverResponse(), web::http::client::SocketContext::deliverResponseParseError(), executeSendFile(), executeSendHeader(), init(), web::http::client::SocketContext::initiateRequest(), web::http::client::SocketContext::onDisconnected(), Request(), web::http::client::SocketContext::requestDelivered(), web::http::client::SocketContext::requestPrepared(), web::http::client::SocketContext::responseDelivered(), responseParseError(), web::http::client::SocketContext::responseStarted(), and web::http::client::SocketContext::~SocketContext().
int web::http::client::Request::httpMinor = 1 |
Definition at line 168 of file Request.h.
Referenced by web::http::client::SocketContext::deliverResponse(), web::http::client::SocketContext::deliverResponseParseError(), executeSendFile(), executeSendHeader(), init(), web::http::client::SocketContext::initiateRequest(), web::http::client::SocketContext::onDisconnected(), Request(), web::http::client::SocketContext::requestDelivered(), web::http::client::SocketContext::requestPrepared(), web::http::client::SocketContext::responseDelivered(), responseParseError(), web::http::client::SocketContext::responseStarted(), and web::http::client::SocketContext::~SocketContext().
|
private |
Definition at line 189 of file Request.h.
Referenced by end(), onSourceConnect(), onSourceEof(), onSourceError(), Request(), requestDelivered(), send(), sendFile(), sendFragment(), sendHeader(), setMasterRequest(), upgrade(), upgrade(), and ~Request().
std::string web::http::client::Request::method = "GET" |
Definition at line 165 of file Request.h.
Referenced by web::http::client::SocketContext::deliverResponse(), web::http::client::SocketContext::deliverResponseParseError(), executeSendHeader(), init(), web::http::client::SocketContext::initiateRequest(), main(), Request(), web::http::client::SocketContext::requestDelivered(), web::http::client::SocketContext::requestPrepared(), web::http::client::SocketContext::responseDelivered(), responseParseError(), web::http::client::SocketContext::responseStarted(), and web::http::client::SocketContext::~SocketContext().
|
private |
Definition at line 187 of file Request.h.
Referenced by deliverResponseParseError(), end(), init(), Request(), send(), sendFile(), and upgrade().
|
private |
Definition at line 186 of file Request.h.
Referenced by deliverResponse(), end(), init(), Request(), send(), sendFile(), and upgrade().
|
protected |
Definition at line 171 of file Request.h.
Referenced by executeSendHeader(), getQueries(), init(), query(), and Request().
|
private |
Definition at line 177 of file Request.h.
Referenced by end(), init(), initiate(), Request(), send(), sendFile(), sendFragment(), sendHeader(), upgrade(), and ~Request().
|
private |
Definition at line 191 of file Request.h.
Referenced by executeSendFragment(), executeSendHeader(), executeUpgrade(), getSocketContext(), onSourceConnect(), onSourceEof(), onSourceError(), Request(), Request(), requestDelivered(), requestPrepared(), upgrade(), and ~Request().
|
protected |
Definition at line 174 of file Request.h.
Referenced by init(), Request(), requestDelivered(), and setTrailer().
|
private |
Definition at line 179 of file Request.h.
Referenced by executeSendFragment(), init(), Request(), requestDelivered(), and set().
std::string web::http::client::Request::url = "/" |
Definition at line 166 of file Request.h.
Referenced by web::http::client::SocketContext::deliverResponse(), web::http::client::SocketContext::deliverResponseParseError(), executeSendHeader(), executeUpgrade(), init(), web::http::client::SocketContext::initiateRequest(), main(), Request(), web::http::client::SocketContext::requestDelivered(), web::http::client::SocketContext::requestPrepared(), web::http::client::SocketContext::responseDelivered(), responseParseError(), web::http::client::SocketContext::responseStarted(), and web::http::client::SocketContext::~SocketContext().