apeters1971 / httpcpp

Lightweight HTTP client using httplib

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

httpcpp

A lightweight HTTP client using httplib (https://github.com/yhirose/cpp-httplib)

Currently it provides a fast GET file streamer implementation using asynchronous programming exporting a filedescriptor interface.

Build it

mkdir build cd build cmake ../ make

httpget

./httpget https://

library

Example how to use the file streamer:

try {
    uri geturi("https://myserver.mydomain//bigfile);

    std::unique_ptr<HttPosixFileStreamer> streamer(new HttPosixFileStreamer);
    int fd = streamer->Open(geturi.get_host(), geturi.get_port(), geturi.get_path());

    // wait for the initial response header
    streamer->WaitHeader();

    // print the status
    std::cout<< "Status: << streamer->Response().status << std::endl;

    // get the size 
    size_t total_s=streamer->Size();

    // read something sequentially from the body
    char buffer[PIPE_BUF];
    auto r = streamer->Read(buffer, sizeof(buffer));
} catch (...) {
  std::cerr << "Invalid URI" << std::endl;
}

About

Lightweight HTTP client using httplib

License:GNU General Public License v3.0


Languages

Language:C++ 99.4%Language:Python 0.3%Language:C 0.2%Language:CMake 0.1%