2019-01-03 05:07:54 +01:00
|
|
|
/*
|
|
|
|
* IXWebSocketHandshake.h
|
|
|
|
* Author: Benjamin Sergeant
|
|
|
|
* Copyright (c) 2019 Machine Zone, Inc. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "IXCancellationRequest.h"
|
2019-05-30 17:46:50 +02:00
|
|
|
#include "IXSocket.h"
|
2019-01-03 05:07:54 +01:00
|
|
|
#include "IXWebSocketHttpHeaders.h"
|
2019-10-13 22:37:34 +02:00
|
|
|
#include "IXWebSocketInitResult.h"
|
2019-01-03 05:07:54 +01:00
|
|
|
#include "IXWebSocketPerMessageDeflate.h"
|
|
|
|
#include "IXWebSocketPerMessageDeflateOptions.h"
|
|
|
|
#include <atomic>
|
|
|
|
#include <chrono>
|
|
|
|
#include <memory>
|
2019-05-30 17:46:50 +02:00
|
|
|
#include <string>
|
2019-01-03 05:07:54 +01:00
|
|
|
|
2019-02-21 03:59:07 +01:00
|
|
|
namespace ix
|
2019-01-03 05:07:54 +01:00
|
|
|
{
|
2019-05-30 17:46:50 +02:00
|
|
|
class WebSocketHandshake
|
|
|
|
{
|
2019-01-03 05:07:54 +01:00
|
|
|
public:
|
|
|
|
WebSocketHandshake(std::atomic<bool>& requestInitCancellation,
|
2020-03-24 20:40:58 +01:00
|
|
|
std::unique_ptr<Socket>& _socket,
|
2020-03-24 02:46:30 +01:00
|
|
|
WebSocketPerMessageDeflatePtr& perMessageDeflate,
|
2019-01-03 05:07:54 +01:00
|
|
|
WebSocketPerMessageDeflateOptions& perMessageDeflateOptions,
|
|
|
|
std::atomic<bool>& enablePerMessageDeflate);
|
|
|
|
|
2019-09-23 19:25:23 +02:00
|
|
|
WebSocketInitResult clientHandshake(const std::string& url,
|
|
|
|
const WebSocketHttpHeaders& extraHeaders,
|
|
|
|
const std::string& host,
|
|
|
|
const std::string& path,
|
|
|
|
int port,
|
|
|
|
int timeoutSecs);
|
2019-01-04 03:33:08 +01:00
|
|
|
|
2021-03-16 17:56:08 +01:00
|
|
|
WebSocketInitResult serverHandshake(int timeoutSecs, bool enablePerMessageDeflate);
|
2019-01-03 05:07:54 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::string genRandomString(const int len);
|
|
|
|
|
|
|
|
// Parse HTTP headers
|
|
|
|
WebSocketInitResult sendErrorResponse(int code, const std::string& reason);
|
|
|
|
|
2019-01-26 01:17:47 +01:00
|
|
|
bool insensitiveStringCompare(const std::string& a, const std::string& b);
|
2019-01-03 22:41:06 +01:00
|
|
|
|
2019-01-03 05:07:54 +01:00
|
|
|
std::atomic<bool>& _requestInitCancellation;
|
2020-03-24 20:40:58 +01:00
|
|
|
std::unique_ptr<Socket>& _socket;
|
2020-03-24 02:46:30 +01:00
|
|
|
WebSocketPerMessageDeflatePtr& _perMessageDeflate;
|
2019-01-03 05:07:54 +01:00
|
|
|
WebSocketPerMessageDeflateOptions& _perMessageDeflateOptions;
|
|
|
|
std::atomic<bool>& _enablePerMessageDeflate;
|
|
|
|
};
|
2019-05-30 17:46:50 +02:00
|
|
|
} // namespace ix
|