fix ws + add doc
This commit is contained in:
parent
c7cb743a69
commit
7b2ddb5e7c
53
README.md
53
README.md
@ -129,33 +129,33 @@ Here is what the HTTP client API looks like. Note that HTTP client support is ve
|
|||||||
// Preparation
|
// Preparation
|
||||||
//
|
//
|
||||||
HttpClient httpClient;
|
HttpClient httpClient;
|
||||||
HttpRequestArgs args;
|
HttpRequestArgsPtr args = httpClient.createRequest();
|
||||||
|
|
||||||
// Custom headers can be set
|
// Custom headers can be set
|
||||||
WebSocketHttpHeaders headers;
|
WebSocketHttpHeaders headers;
|
||||||
headers["Foo"] = "bar";
|
headers["Foo"] = "bar";
|
||||||
args.extraHeaders = headers;
|
args->extraHeaders = headers;
|
||||||
|
|
||||||
// Timeout options
|
// Timeout options
|
||||||
args.connectTimeout = connectTimeout;
|
args->connectTimeout = connectTimeout;
|
||||||
args.transferTimeout = transferTimeout;
|
args->transferTimeout = transferTimeout;
|
||||||
|
|
||||||
// Redirect options
|
// Redirect options
|
||||||
args.followRedirects = followRedirects;
|
args->followRedirects = followRedirects;
|
||||||
args.maxRedirects = maxRedirects;
|
args->maxRedirects = maxRedirects;
|
||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
args.compress = compress; // Enable gzip compression
|
args->compress = compress; // Enable gzip compression
|
||||||
args.verbose = verbose;
|
args->verbose = verbose;
|
||||||
args.logger = [](const std::string& msg)
|
args->logger = [](const std::string& msg)
|
||||||
{
|
{
|
||||||
std::cout << msg;
|
std::cout << msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// Request
|
// Synchronous Request
|
||||||
//
|
//
|
||||||
HttpResponse out;
|
HttpResponsePtr out;
|
||||||
std::string url = "https://www.google.com";
|
std::string url = "https://www.google.com";
|
||||||
|
|
||||||
// HEAD request
|
// HEAD request
|
||||||
@ -175,13 +175,30 @@ out = httpClient.post(url, std::string("foo=bar"), args);
|
|||||||
//
|
//
|
||||||
// Result
|
// Result
|
||||||
//
|
//
|
||||||
auto statusCode = std::get<0>(out);
|
auto errorCode = response->errorCode; // Can be HttpErrorCode::Ok, HttpErrorCode::UrlMalformed, etc...
|
||||||
auto errorCode = std::get<1>(out);
|
auto errorCode = response->errorCode; // 200, 404, etc...
|
||||||
auto responseHeaders = std::get<2>(out);
|
auto responseHeaders = response->headers; // All the headers in a special case-insensitive unordered_map of (string, string)
|
||||||
auto payload = std::get<3>(out);
|
auto payload = response->payload; // All the bytes from the response as an std::string
|
||||||
auto errorMsg = std::get<4>(out);
|
auto errorMsg = response->errorMsg; // Descriptive error message in case of failure
|
||||||
auto uploadSize = std::get<5>(out);
|
auto uploadSize = response->uploadSize; // Byte count of uploaded data
|
||||||
auto downloadSize = std::get<6>(out);
|
auto downloadSize = response->downloadSize; // Byte count of downloaded data
|
||||||
|
|
||||||
|
//
|
||||||
|
// Asynchronous Request
|
||||||
|
//
|
||||||
|
bool async = true;
|
||||||
|
HttpClient httpClient(async);
|
||||||
|
auto args = httpClient.createRequest(url, HttpClient::kGet);
|
||||||
|
|
||||||
|
// Push the request to a queue,
|
||||||
|
bool ok = httpClient.performRequest(args, [](const HttpResponsePtr& response)
|
||||||
|
{
|
||||||
|
// This callback execute in a background thread. Make sure you uses appropriate protection such as mutex
|
||||||
|
auto statusCode = response->statusCode; // acess results
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// ok will be false if your httpClient is not async
|
||||||
```
|
```
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
23
docker/Dockerfile.ubuntu_bionic
Normal file
23
docker/Dockerfile.ubuntu_bionic
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Build time
|
||||||
|
FROM ubuntu:bionic as build
|
||||||
|
|
||||||
|
ENV DEBIAN_FRONTEND noninteractive
|
||||||
|
RUN apt-get update
|
||||||
|
RUN apt-get -y install wget
|
||||||
|
RUN mkdir -p /tmp/cmake
|
||||||
|
WORKDIR /tmp/cmake
|
||||||
|
RUN wget https://github.com/Kitware/CMake/releases/download/v3.14.0/cmake-3.14.0-Linux-x86_64.tar.gz
|
||||||
|
RUN tar zxf cmake-3.14.0-Linux-x86_64.tar.gz
|
||||||
|
|
||||||
|
RUN apt-get -y install g++
|
||||||
|
RUN apt-get -y install libssl-dev
|
||||||
|
RUN apt-get -y install libz-dev
|
||||||
|
RUN apt-get -y install make
|
||||||
|
RUN apt-get -y install python
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
ARG CMAKE_BIN_PATH=/tmp/cmake/cmake-3.14.0-Linux-x86_64/bin
|
||||||
|
ENV PATH="${CMAKE_BIN_PATH}:${PATH}"
|
||||||
|
|
||||||
|
RUN ["make", "ws"]
|
@ -82,7 +82,7 @@ namespace ix
|
|||||||
mbedtls_ssl_set_bio(&_ssl, &_sockfd, mbedtls_net_send, mbedtls_net_recv, NULL);
|
mbedtls_ssl_set_bio(&_ssl, &_sockfd, mbedtls_net_send, mbedtls_net_recv, NULL);
|
||||||
|
|
||||||
int res;
|
int res;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
res = mbedtls_ssl_handshake(&_ssl);
|
res = mbedtls_ssl_handshake(&_ssl);
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ namespace ix
|
|||||||
{
|
{
|
||||||
_onMessageUserCallback = std::move(callback);
|
_onMessageUserCallback = std::move(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
WebSocketMessageQueue::MessagePtr WebSocketMessageQueue::popMessage()
|
WebSocketMessageQueue::MessagePtr WebSocketMessageQueue::popMessage()
|
||||||
{
|
{
|
||||||
MessagePtr message;
|
MessagePtr message;
|
||||||
|
@ -1041,7 +1041,7 @@ namespace ix
|
|||||||
_requestInitCancellation = true;
|
_requestInitCancellation = true;
|
||||||
|
|
||||||
if (_readyState == ReadyState::CLOSING || _readyState == ReadyState::CLOSED) return;
|
if (_readyState == ReadyState::CLOSING || _readyState == ReadyState::CLOSED) return;
|
||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(_closeDataMutex);
|
std::lock_guard<std::mutex> lock(_closeDataMutex);
|
||||||
_closeCode = code;
|
_closeCode = code;
|
||||||
|
@ -210,7 +210,7 @@ namespace
|
|||||||
<< closeInfo.reason
|
<< closeInfo.reason
|
||||||
<< ")";
|
<< ")";
|
||||||
log(ss.str());
|
log(ss.str());
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lck(mutexWrite);
|
std::lock_guard<std::mutex> lck(mutexWrite);
|
||||||
|
|
||||||
receivedCloseCode = closeInfo.code;
|
receivedCloseCode = closeInfo.code;
|
||||||
|
Loading…
Reference in New Issue
Block a user