Git Product home page Git Product logo

cpp20-http-client's Issues

How to follow URLs when using send_async?

Currently my implementation is following your example code.

But now the question becomes, how to keep the redirect working and using your send_async call? So using send_async<256>(); etc. And at the same time it should keep following those 30x status responses.

Using:

while (true) {
    // Do request...
    std::string url("<some initial URL..>");
    const auto response = http_client::get(url).sent();

    // Follow 30x status codes
    if (response.get_status_code() == http_client::StatusCode::MovedPermanently ||
        response.get_status_code() == http_client::StatusCode::Found) 
    {
        if (auto const new_url = response.get_header_value("location")) {
            url = *new_url; // Override URL
            continue;
        }
    } else { ... }
    break;
}

Fix compiler warnings

This project has some minor compiler warnings (I'm using GCC 11.3.0), maybe it's not too difficult to solve them. I'm using the following compiler flags in CMake:

add_compile_options(-Wall -Wextra -pedantic)

set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
[build] /some_folder/build/_deps/cpp20httpclient-src/include/cpp20_http_client.hpp: In function ‘http_client::utils::HostAndPort http_client::utils::split_domain_name(std::string_view)’:
[build] /some_folder/build/_deps/cpp20httpclient-src/include/cpp20_http_client.hpp:511:25: warning: missing initializer for member ‘http_client::utils::HostAndPort::port’ [-Wmissing-field-initializers]
[build]   511 |                         };
[build]       |                         ^
[build] /some_folder/build/_deps/cpp20httpclient-src/include/cpp20_http_client.hpp:516:9: warning: missing initializer for member ‘http_client::utils::HostAndPort::port’ [-Wmissing-field-initializers]
[build]   516 |         };
[build]       |         ^
[build] /some_folder/build/_deps/cpp20httpclient-src/include/cpp20_http_client.hpp: In function ‘constexpr bool http_client::utils::get_is_allowed_uri_character(char)’:
[build] /some_folder/build/_deps/cpp20httpclient-src/include/cpp20_http_client.hpp:614:33: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
[build]   614 |         return character >= '0' && character <= '9' ||
[build]       |                ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
[build] /some_folder/build/_deps/cpp20httpclient-src/include/cpp20_http_client.hpp:616:34: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
[build]   616 |                 character >= 'A' && character <= 'Z' ||
[build]       |                 ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~

Do not build and link the examples

I'm using your library via FetchContent. But it seems that the examples folder is getting build & linked to my binary. I don't think this is wanted behavior. Maybe a simple CMake flag can help disabling building/linking the examples?

[build] [8/16   6% :: 5.183] Building CXX object _deps/cpp20httpclient-build/examples/CMakeFiles/example_get_request_simple.dir/get_request_simple.cpp.o
[build] [8/16  12% :: 5.218] Building CXX object _deps/cpp20httpclient-build/examples/CMakeFiles/example_socket.dir/socket.cpp.o
[build] [8/16  18% :: 5.587] Building CXX object _deps/cpp20httpclient-build/examples/CMakeFiles/example_async_get_request.dir/async_get_request.cpp.o
[build] [8/16  25% :: 5.601] Building CXX object _deps/cpp20httpclient-build/examples/CMakeFiles/example_post_request.dir/post_request.cpp.o
[build] [8/16  31% :: 6.318] Building CXX object _deps/cpp20httpclient-build/CMakeFiles/cpp20_http_client.dir/source/cpp20_http_client.cpp.o
[build] [9/16  37% :: 6.373] Linking CXX static library _deps/cpp20httpclient-build/lib/libcpp20_http_client.a
[build] [13/16  43% :: 6.555] Building CXX object CMakeFiles/project_name.dir/src/main.cpp.o
[build] [14/16  50% :: 6.555] Linking CXX executable _deps/cpp20httpclient-build/bin/example_socket
[build] [14/16  56% :: 6.632] Linking CXX executable _deps/cpp20httpclient-build/bin/example_get_request_simple
[build] [14/16  62% :: 6.634] Linking CXX executable _deps/cpp20httpclient-build/bin/example_post_request
[build] [14/16  68% :: 6.639] Linking CXX executable _deps/cpp20httpclient-build/bin/example_async_get_request
[build] [14/16  75% :: 6.754] Linking CXX executable binary_name
[build] [14/16  81% :: 6.941] Building CXX object _deps/cpp20httpclient-build/examples/CMakeFiles/example_get_request.dir/get_request.cpp.o
[build] [15/16  87% :: 7.071] Linking CXX executable _deps/cpp20httpclient-build/bin/example_get_request
[build] [15/16  93% :: 7.200] Building CXX object _deps/cpp20httpclient-build/examples/CMakeFiles/example_async_simple.dir/async_simple.cpp.o
[build] [16/16 100% :: 7.330] Linking CXX executable _deps/cpp20httpclient-build/bin/example_async_simple

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.