Skip to content

Commit

Permalink
Merge pull request #12 from Neko-Life/patch/jaskowicz1/sslclient-changes
Browse files Browse the repository at this point in the history
Patch/jaskowicz1/sslclient changes
  • Loading branch information
Jaskowicz1 authored Sep 24, 2023
2 parents 59ee7d7 + 2917587 commit 3da14ae
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
8 changes: 8 additions & 0 deletions include/dpp/httpsclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@
#include <vector>
#include <variant>
#include <dpp/sslclient.h>
#include <dpp/version.h>
#include <dpp/stringops.h>

namespace dpp {

static inline const std::string http_version = "DiscordBot (https://github.com/brainboxdotcc/DPP, "
+ to_hex(DPP_VERSION_MAJOR) + "."
+ to_hex(DPP_VERSION_MINOR) + "."
+ to_hex(DPP_VERSION_PATCH) + ")";

static inline constexpr const char* DISCORD_HOST = "https://discord.com";

/**
* @brief HTTP connection status
Expand Down
4 changes: 0 additions & 4 deletions src/dpp/queues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@
#include <dpp/cluster.h>
#include <dpp/httpsclient.h>
#include <dpp/stringops.h>
#include <dpp/version.h>

namespace dpp {

static std::string http_version = "DiscordBot (https://github.com/brainboxdotcc/DPP, " + std::to_string(DPP_VERSION_MAJOR) + "." + std::to_string(DPP_VERSION_MINOR) + "." + std::to_string(DPP_VERSION_PATCH) + ")";
static const char* DISCORD_HOST = "https://discord.com";

http_request::http_request(const std::string &_endpoint, const std::string &_parameters, http_completion_event completion, const std::string &_postdata, http_method _method, const std::string &audit_reason, const std::string &filename, const std::string &filecontent, const std::string &filemimetype)
: complete_handler(completion), completed(false), non_discord(false), endpoint(_endpoint), parameters(_parameters), postdata(_postdata), method(_method), reason(audit_reason), mimetype("application/json"), waiting(false)
{
Expand Down
1 change: 0 additions & 1 deletion src/dpp/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include <thread>
#include <functional>
#include <chrono>
#include <ctime>
#include <algorithm>
#include <fstream>
#include <streambuf>
Expand Down
3 changes: 2 additions & 1 deletion src/dpp/wsclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <fstream>
#include <dpp/wsclient.h>
#include <dpp/utility.h>
#include <dpp/httpsclient.h>

namespace dpp {

Expand Down Expand Up @@ -52,7 +53,7 @@ void websocket_client::connect()
"GET " + this->path + " HTTP/1.1\r\n"
"Host: " + this->hostname + "\r\n"
"pragma: no-cache\r\n"
"User-Agent: " + "DiscordBot (https://github.com/brainboxdotcc/DPP, 16.0.38)" + "\r\n"
"User-Agent: " + http_version + "\r\n"
"Upgrade: WebSocket\r\n"
"Connection: Upgrade\r\n"
"Sec-WebSocket-Key: " + this->key + "\r\n"
Expand Down
14 changes: 10 additions & 4 deletions src/unittest/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,16 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b
set_test(READFILE, false);
std::string rf_test = dpp::utility::read_file(SHARED_OBJECT);
FILE* fp = fopen(SHARED_OBJECT, "rb");
fseek(fp, 0, SEEK_END);
size_t off = (size_t)ftell(fp);
fclose(fp);
set_test(READFILE, off == rf_test.length());
if (!fp) {
std::cout << "READFILE: Failed to open file: " << SHARED_OBJECT << "\n";
set_test(READFILE, false);
}
else {
fseek(fp, 0, SEEK_END);
size_t off = (size_t)ftell(fp);
fclose(fp);
set_test(READFILE, off == rf_test.length());
}

set_test(TIMESTAMPTOSTRING, false);
set_test(TIMESTAMPTOSTRING, dpp::ts_to_string(1642611864) == "2022-01-19T17:04:24Z");
Expand Down

0 comments on commit 3da14ae

Please sign in to comment.