Skip to content
This repository has been archived by the owner on Jun 24, 2023. It is now read-only.

Commit

Permalink
gzip data
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWillard committed Dec 25, 2020
1 parent e9b6ec7 commit d01b901
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
#setupOnly: true
vcpkgDirectory: '${{ github.workspace }}/vcpkg'
vcpkgTriplet: '${{ matrix.triplet }}'
vcpkgArguments: 'nlohmann-json boost-program-options boost-property-tree cpr'
vcpkgArguments: 'nlohmann-json boost-program-options boost-property-tree boost-iostreams cpr'
vcpkgGitCommitId: 'acb6b10e7fdf5e8519c18398d0b069e1d58ca025'

# Build with CMake and Ninja
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ find_package(cpr CONFIG REQUIRED)

# Boost
set(Boost_USE_STATIC_LIBS ON)
FIND_PACKAGE(Boost 1.69 COMPONENTS program_options REQUIRED)
FIND_PACKAGE(Boost 1.69 COMPONENTS program_options iostreams REQUIRED)

#include the Intercept headers from the submodule
set(INTERCEPT_CLIENT_PATH "${CMAKE_SOURCE_DIR}/intercept/src/client")
Expand Down
35 changes: 25 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>

// Gzip
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>

#include <string>
#include <iostream>
#include <sstream>
Expand All @@ -26,6 +31,7 @@ static inline std::string GRAD_REPLAY_USER_AGENT = "grad_replay_intercept/" +

namespace nl = nlohmann;
namespace fs = std::filesystem;
namespace bi = boost::iostreams;

using namespace intercept;
using namespace grad::replay;
Expand Down Expand Up @@ -183,21 +189,30 @@ game_value sendReplay(game_state& gs, SQFPar right_arg) {
std::thread sendReplayThread([obj, now]() {
try
{
std::stringstream ss;
ss << obj;

auto header = cpr::Header{
{"Content-Type","application/json"},
{"content-length", std::to_string(ss.str().size())},
{"Connection", "close"},
{"Authorization", std::string("Bearer ").append(token)},
{"User-Agent", GRAD_REPLAY_USER_AGENT}
std::stringstream inputStream(obj.dump());

bi::filtering_istream fis;
fis.push(bi::gzip_compressor(bi::gzip_params(bi::gzip::best_compression)));
fis.push(inputStream);

std::stringstream outputStream;
bi::copy(fis, outputStream);

std::string outputString(outputStream.str());

auto header = cpr::Header {
{ "Content-Type", "application/json" },
{ "Content-Encoding", "gzip" },
{ "Content-Length", std::to_string(outputString.size()) },
{ "Connection", "close" },
{ "Authorization", std::string("Bearer ").append(token) },
{ "User-Agent", GRAD_REPLAY_USER_AGENT }
};

cpr::Response response = cpr::Post(
cpr::Url{ url },
header,
cpr::Body(ss.str()),
cpr::Body(outputString),
cpr::Timeout(60000)
);

Expand Down

0 comments on commit d01b901

Please sign in to comment.