add http_header class and bot::http namespace

This commit is contained in:
Syping 2026-03-29 07:32:37 +02:00
parent f12e13ed28
commit e98bd9de6c
14 changed files with 185 additions and 72 deletions

View file

@ -17,9 +17,10 @@
*****************************************************************************/
#include <dpp/json.h>
#include <dpp/httpsclient.h>
#include <iostream>
#include "../../core/http_request.h"
#include "deepl.h"
using namespace bot::http;
using namespace bot::translator;
using namespace std::chrono_literals;
@ -43,7 +44,8 @@ const std::vector<language> deepl::get_languages()
try {
http_request request;
http_response response = request.get(http_request::legacy_url(m_hostname, 443, "/v2/languages?type=target", true), { {"Authorization", "DeepL-Auth-Key " + m_apiKey} });
http_response response = request.get(http_request::legacy_url(m_hostname, 443, "/v2/languages?type=target", true),
{{"Authorization", "DeepL-Auth-Key " + m_apiKey}});
if (response.status == 200) {
const dpp::json json_response = dpp::json::parse(response.content);
if (json_response.is_array()) {
@ -91,7 +93,8 @@ const std::string deepl::translate(const std::string &text, const std::string &s
try {
http_request request;
http_response response = request.post(http_request::legacy_url(m_hostname, 443, "/v2/translate", true), json_body.dump(), "application/json", { {"Authorization", "DeepL-Auth-Key " + m_apiKey} });
http_response response = request.post(http_request::legacy_url(m_hostname, 443, "/v2/translate", true), json_body.dump(),
{{"Authorization", "DeepL-Auth-Key " + m_apiKey}, {"Content-Type", "application/json"}});
if (response.status == 200) {
const dpp::json json_response = dpp::json::parse(response.content);
if (json_response.is_object()) {