ws connect has a new option to send HTTP headers + use WebSocketHttpHeaders instead of unordered_map<string, string>

This commit is contained in:
Benjamin Sergeant
2019-08-26 10:19:09 -07:00
parent 2e32319236
commit 45d7bb34d7
12 changed files with 66 additions and 12 deletions

View File

@ -70,7 +70,7 @@ namespace ix
std::lock_guard<std::mutex> lock(_configMutex);
_url = url;
}
void WebSocket::setExtraHeaders(const std::unordered_map<std::string, std::string>& headers)
void WebSocket::setExtraHeaders(const WebSocketHttpHeaders& headers)
{
std::lock_guard<std::mutex> lock(_configMutex);
_extraHeaders = headers;

View File

@ -21,7 +21,6 @@
#include <mutex>
#include <string>
#include <thread>
#include <unordered_map>
namespace ix
{
@ -45,8 +44,9 @@ namespace ix
~WebSocket();
void setUrl(const std::string& url);
void setExtraHeaders(const std::unordered_map<std::string, std::string>&
headers); // send extra headers in client handshake request
// send extra headers in client handshake request
void setExtraHeaders(const WebSocketHttpHeaders& headers);
void setPerMessageDeflateOptions(
const WebSocketPerMessageDeflateOptions& perMessageDeflateOptions);
void setHeartBeatPeriod(int heartBeatPeriodSecs);
@ -114,7 +114,7 @@ namespace ix
WebSocketTransport _ws;
std::string _url;
std::unordered_map<std::string, std::string> _extraHeaders;
WebSocketHttpHeaders _extraHeaders;
WebSocketPerMessageDeflateOptions _perMessageDeflateOptions;
mutable std::mutex _configMutex; // protect all config variables access

View File

@ -88,7 +88,7 @@ namespace ix
}
WebSocketInitResult WebSocketHandshake::clientHandshake(const std::string& url,
const std::unordered_map<std::string, std::string>& extraHeaders,
const WebSocketHttpHeaders& extraHeaders,
const std::string& host,
const std::string& path,
int port,

View File

@ -53,7 +53,7 @@ namespace ix
WebSocketInitResult clientHandshake(
const std::string& url,
const std::unordered_map<std::string, std::string>& extraHeaders,
const WebSocketHttpHeaders& extraHeaders,
const std::string& host,
const std::string& path,
int port,

View File

@ -129,7 +129,7 @@ namespace ix
// Client
WebSocketInitResult WebSocketTransport::connectToUrl(
const std::string& url,
const std::unordered_map<std::string, std::string>& headers,
const WebSocketHttpHeaders& headers,
int timeoutSecs)
{
std::lock_guard<std::mutex> lock(_socketMutex);

View File

@ -24,7 +24,7 @@
#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>
#include <vector>
namespace ix
@ -78,7 +78,7 @@ namespace ix
WebSocketInitResult connectToUrl( // Client
const std::string& url,
const std::unordered_map<std::string, std::string>& headers,
const WebSocketHttpHeaders& headers,
int timeoutSecs);
WebSocketInitResult connectToSocket(int fd, // Server
int timeoutSecs);