fix ws + add doc

This commit is contained in:
Benjamin Sergeant 2019-06-05 16:04:51 -07:00
parent c7cb743a69
commit 7b2ddb5e7c
6 changed files with 62 additions and 22 deletions

View File

@ -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

View 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"]