Skip to content

Commit

Permalink
make fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
web-flow authored Mar 14, 2024
1 parent ef10103 commit 831e849
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 38 deletions.
69 changes: 32 additions & 37 deletions silkworm/rpc/http/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

#include "connection.hpp"

#include <zlib.h>

#include <array>
#include <exception>
#include <string_view>

#include <zlib.h>

#include <boost/asio/buffer.hpp>
#include <boost/asio/detached.hpp>
#include <boost/asio/use_awaitable.hpp>
Expand Down Expand Up @@ -194,10 +194,10 @@ Task<void> Connection::handle_actual_request(const boost::beast::http::request<b
method_ = req.method();
auto encoding = req[boost::beast::http::field::accept_encoding];

if(!encoding.empty()) {
if (!encoding.empty()) {
std::cout << "AcceptEncoding: " << encoding << "\n";
std::string clear_data;
clear_data.resize(10*1024*1024);
clear_data.resize(10 * 1024 * 1024);
auto ret = uncompress_data(req.body(), clear_data);
if (ret >= 0) {
auto rsp_content = co_await request_handler_.handle(clear_data);
Expand All @@ -207,7 +207,6 @@ Task<void> Connection::handle_actual_request(const boost::beast::http::request<b
}
}


auto rsp_content = co_await request_handler_.handle(req.body());
if (rsp_content) {
co_await do_write(rsp_content->append("\n"), boost::beast::http::status::ok);
Expand Down Expand Up @@ -287,7 +286,7 @@ Task<void> Connection::do_write(const std::string& content, boost::beast::http::
std::cout << "AcceptEncoding: " << coded << "\n";
res.set(boost::beast::http::field::content_encoding, coded);
std::string coded_data;
coded_data.resize(10*1024*1024);
coded_data.resize(10 * 1024 * 1024);
auto ret = compress_data(content, coded_data);
if (ret >= 0) {
res.content_length(coded_data.size());
Expand Down Expand Up @@ -319,69 +318,65 @@ Task<void> Connection::do_write(const std::string& content, boost::beast::http::

long Connection::compress_data(std::string clear_data, std::string compressed_data) {
z_stream strm;
strm.zalloc=nullptr;
strm.zfree=nullptr;
strm.opaque=nullptr;
strm.zalloc = nullptr;
strm.zfree = nullptr;
strm.opaque = nullptr;

strm.avail_in = static_cast<unsigned int>(clear_data.size());
strm.avail_out = static_cast<unsigned int>(compressed_data.size());

auto ptr_clear = const_cast<char *> (clear_data.c_str());
strm.next_in = reinterpret_cast<Bytef *> (ptr_clear);
auto ptr_clear = const_cast<char*>(clear_data.c_str());
strm.next_in = reinterpret_cast<Bytef*>(ptr_clear);

auto ptr_coded = const_cast<char *> (compressed_data.c_str());
strm.next_out = reinterpret_cast<Bytef *> (ptr_coded);
auto ptr_coded = const_cast<char*>(compressed_data.c_str());
strm.next_out = reinterpret_cast<Bytef*>(ptr_coded);

int err=Z_OK;
err = inflateInit2(&strm, MAX_WBITS+16);
if (err == Z_OK){
int err = Z_OK;
err = inflateInit2(&strm, MAX_WBITS + 16);
if (err == Z_OK) {
err = inflate(&strm, Z_FINISH);
if (err == Z_STREAM_END){
if (err == Z_STREAM_END) {
auto ret = strm.total_out;
inflateEnd(&strm);
return static_cast<long>(ret);
}
else{
} else {
inflateEnd(&strm);
return err;
}
}
else{
} else {
inflateEnd(&strm);
return err;
}
}

long Connection::uncompress_data(std::string compressed_data, std::string clear_data){
long Connection::uncompress_data(std::string compressed_data, std::string clear_data) {
z_stream strm;
strm.zalloc=nullptr;
strm.zfree=nullptr;
strm.opaque=nullptr;
strm.zalloc = nullptr;
strm.zfree = nullptr;
strm.opaque = nullptr;

strm.avail_in = static_cast<unsigned int>(compressed_data.size());
strm.avail_out = static_cast<unsigned int>(clear_data.size());

auto ptr_coded = const_cast<char *> (compressed_data.c_str());
strm.next_in = reinterpret_cast<Bytef *> (ptr_coded);
auto ptr_coded = const_cast<char*>(compressed_data.c_str());
strm.next_in = reinterpret_cast<Bytef*>(ptr_coded);

auto ptr_clear = const_cast<char *> (clear_data.c_str());
strm.next_out = reinterpret_cast<Bytef *> (ptr_clear);
auto ptr_clear = const_cast<char*>(clear_data.c_str());
strm.next_out = reinterpret_cast<Bytef*>(ptr_clear);

int err=Z_OK;
err = deflateInit(&strm, MAX_WBITS+16);
if (err == Z_OK){
int err = Z_OK;
err = deflateInit(&strm, MAX_WBITS + 16);
if (err == Z_OK) {
err = deflate(&strm, Z_FINISH);
if (err == Z_STREAM_END){
if (err == Z_STREAM_END) {
auto ret = strm.total_out;
inflateEnd(&strm);
return static_cast<long>(ret);
}
else{
} else {
inflateEnd(&strm);
return err;
}
}
else{
} else {
inflateEnd(&strm);
return err;
}
Expand Down
2 changes: 1 addition & 1 deletion silkworm/rpc/http/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Connection : public StreamWriter {
Task<bool> do_read();

//! Perform an asynchronous write operation.
Task<void> do_write(const std::string& content, boost::beast::http::status http_status, bool compress=false);
Task<void> do_write(const std::string& content, boost::beast::http::status http_status, bool compress = false);

static std::string get_date_time();

Expand Down

0 comments on commit 831e849

Please sign in to comment.