Skip to content

HTTP request bodies randomly gets cut off in Windows #1382

@null8626

Description

@null8626

Describe the bug
HTTP request bodies done with dpp::cluster::request randomly gets cut off in Windows.

To Reproduce
I am currently using the latest version of D++ obtained from dl.dpp.dev, version 10.1.0.

#include <dpp/dpp.h>

#include <semaphore>
#include <iostream>
#include <cstdlib>
#include <utility>

static std::binary_semaphore g_sem{0};

int main() {
  const auto discord_token{std::getenv("BOT_TOKEN")};

  if (discord_token == nullptr) {
    std::cerr << "error: missing BOT_TOKEN environment variable" << std::endl;
    return 1;
  }

  dpp::cluster bot{discord_token};

  bot.start(dpp::start_type::st_return);

  dpp::http_headers headers{};

  headers.insert(std::pair("Authorization", "top.gg API token"));
  headers.insert(std::pair("Connection", "close"));
  headers.insert(std::pair("Content-Type", "application/json"));
  headers.insert(std::pair("User-Agent", "topgg (https://github.com/top-gg-community/cpp-sdk) D++"));

  bot.request("https://top.gg/api/bots/264811613708746752", dpp::http_method::m_get, [](const auto& response) {
    std::cout << "===BODY START===\n" << response.body << "\n===BODY END===\nSIZE: " << response.body.size() << std::endl;
    g_sem.release();
  }, "", "application/json", headers);

  g_sem.acquire();

  return 0;
}

Expected behavior
The HTTP request should've retrieved the whole body. This request sometimes only gives less body than expected, and the difference between requests is usually random.

For example, when I ran the code above, I got:

  • 2,041 bytes
  • 3,746 bytes (the entire body as expected)
  • 3,746 bytes (the entire body as expected)
  • 3,410 bytes

Screenshots
First iteration:
Image

Second and third iteration:
Image

No re-compilations were done between iterations, I simply reran the executable.

System Details:

  • OS: Windows 11, compiled with Microsoft Visual C++ under Visual Studio 2022
  • Discord Client: None -- I was using dpp::cluster purely to test dpp::cluster::request.

Additional context
I was testing the Top.gg C++ SDK and needed dpp::cluster::request to send requests to the Top.gg API.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions