SNode.C
Loading...
Searching...
No Matches
web::websocket::client::SocketContextUpgradeFactory Class Reference

#include <SocketContextUpgradeFactory.h>

Inheritance diagram for web::websocket::client::SocketContextUpgradeFactory:
Collaboration diagram for web::websocket::client::SocketContextUpgradeFactory:

Public Member Functions

 SocketContextUpgradeFactory ()=default
 
- Public Member Functions inherited from web::http::client::SocketContextUpgradeFactory
void checkRefCount () final
 
- Public Member Functions inherited from core::socket::stream::SocketContextFactory
 SocketContextFactory (SocketContextFactory &)=delete
 
 SocketContextFactory (SocketContextFactory &&)=delete
 
SocketContextFactoryoperator= (SocketContextFactory &)=delete
 
SocketContextFactoryoperator= (SocketContextFactory &&)=delete
 

Static Public Member Functions

static void link ()
 
- Static Public Member Functions inherited from web::http::client::SocketContextUpgradeFactory
static void link (const std::string &upgradeContextName, SocketContextUpgradeFactory *(*linkedPlugin)())
 

Private Member Functions

void prepare (web::http::client::Request &request) override
 
std::string name () override
 
http::SocketContextUpgrade< web::http::client::Request, web::http::client::Response > * create (core::socket::stream::SocketConnection *socketConnection, web::http::client::Request *request, web::http::client::Response *response) override
 

Additional Inherited Members

- Public Types inherited from web::http::client::SocketContextUpgradeFactory
using Resquest = web::http::client::Request
 
using Reponse = web::http::client::Response
 
- Public Types inherited from web::http::SocketContextUpgradeFactory< web::http::client::Request, web::http::client::Response >
using Request
 
using Response
 
- Protected Member Functions inherited from web::http::client::SocketContextUpgradeFactory
 SocketContextUpgradeFactory ()
 
- Protected Member Functions inherited from web::http::SocketContextUpgradeFactory< web::http::client::Request, web::http::client::Response >
 SocketContextUpgradeFactory ()=default
 
 ~SocketContextUpgradeFactory () override=default
 
void prepare (Request &request, Response &response)
 
- Protected Member Functions inherited from core::socket::stream::SocketContextFactory
 SocketContextFactory ()=default
 
virtual ~SocketContextFactory ()
 
- Protected Attributes inherited from web::http::SocketContextUpgradeFactory< web::http::client::Request, web::http::client::Response >
std::size_t refCount
 

Detailed Description

Definition at line 33 of file SocketContextUpgradeFactory.h.

Constructor & Destructor Documentation

◆ SocketContextUpgradeFactory()

web::websocket::client::SocketContextUpgradeFactory::SocketContextUpgradeFactory ( )
default

Member Function Documentation

◆ create()

http::SocketContextUpgrade< web::http::client::Request, web::http::client::Response > * web::websocket::client::SocketContextUpgradeFactory::create ( core::socket::stream::SocketConnection * socketConnection,
web::http::client::Request * request,
web::http::client::Response * response )
overrideprivatevirtual

Implements web::http::SocketContextUpgradeFactory< web::http::client::Request, web::http::client::Response >.

Definition at line 49 of file SocketContextUpgradeFactory.cpp.

51 {
52 SocketContextUpgrade* socketContext = nullptr;
53
54 if (response->get("sec-websocket-accept") == base64::serverWebSocketKey(request->header("Sec-WebSocket-Key"))) {
55 const std::string subProtocolName = response->get("sec-websocket-protocol");
56
57 socketContext = new SocketContextUpgrade(socketConnection, this);
58 const std::string selectedSubProtocolName = socketContext->loadSubProtocol(subProtocolName);
59
60 if (selectedSubProtocolName.empty()) {
61 delete socketContext;
62 socketContext = nullptr;
63 }
64 } else {
66 }
67
68 return socketContext;
69 }
std::string header(const std::string &field)
Definition Request.cpp:616
const std::string & get(const std::string &key, int i=0) const
Definition Response.cpp:31
std::string serverWebSocketKey(const std::string &clientWebSocketKey)
Definition base64.cpp:34

◆ link()

void web::websocket::client::SocketContextUpgradeFactory::link ( )
static

Definition at line 71 of file SocketContextUpgradeFactory.cpp.

71 {
72 static bool linked = false;
73
74 if (!linked) {
76 linked = true;
77 }
78 }
static void link(const std::string &upgradeContextName, SocketContextUpgradeFactory *(*linkedPlugin)())
web::http::client::SocketContextUpgradeFactory * websocketClientSocketContextUpgradeFactory()

◆ name()

std::string web::websocket::client::SocketContextUpgradeFactory::name ( )
overrideprivatevirtual

◆ prepare()

void web::websocket::client::SocketContextUpgradeFactory::prepare ( web::http::client::Request & request)
overrideprivatevirtual

Implements web::http::client::SocketContextUpgradeFactory.

Definition at line 36 of file SocketContextUpgradeFactory.cpp.

36 {
37 unsigned char ebytes[16];
38 getentropy(ebytes, 16);
39
40 request.set("Sec-WebSocket-Key", base64::base64_encode(ebytes, 16));
41 request.set("Sec-WebSocket-Version", "13");
42 }
Request & set(const std::string &field, const std::string &value, bool overwrite=true)
Definition Request.cpp:137
std::string base64_encode(const unsigned char *bytes_to_encode, std::size_t length)
Definition base64.cpp:47

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