Skip to content

Instantly share code, notes, and snippets.

View deanberris's full-sized avatar

Dean Michael Berris deanberris

View GitHub Profile
@deanberris
deanberris / http-server-example.cc
Created September 25, 2012 12:35
HTTP Server Example
namespace http = network::http;
http::server server_;
server_.register_handler(
"/hello", [](session& s, std::shared_ptr<connection> c) {
c->response().write(s["user"].empty()? string("world!") : s["user"]);
});
server_.register_handler(
"/echo", [](session& s, std::shared_ptr<connection> c) {
if (c->method() != http::server::POST) {
c->response().write("echo!");
@deanberris
deanberris / simple-client.cc
Created September 25, 2012 12:23
Simple HTTP Client API
namespace http = network::http;
http::client client;
auto response = client.get("https://www.example.com/foo");
@deanberris
deanberris / request-configuration.cc
Created September 25, 2012 12:13
Request Configuration
namespace http = network::http;
http::request_options ro;
ro.timeout(std::chrono::duration(30))
.client_cert("/tmp/my_cert.pem")
.accept_transfer_encoding({http::transfer_encodings::gzip, http::transfer_encodings::plain});
auto response = client.get("https://www.example.com/foo", ro);
@deanberris
deanberris / configuration-sample.cc
Created September 25, 2012 11:58
Configuration Type Pattern
namespace http = network::http;
http::client_options options;
options.follow_redirects(true)
.accept_encoding({"*/*"})
.version(http::version::http_1_1)
.proxy("localhost:8080")
.idle_timeout(30);
http::client client{options};