Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpcdaemon: add HTTP gzip compression (no streaming) #1909

Merged
merged 3 commits into from
Mar 16, 2024

Conversation

lupin012
Copy link
Contributor

No description provided.

@lupin012 lupin012 added the enhancement New feature or improvement label Mar 14, 2024
@lupin012 lupin012 force-pushed the http_compression_no_streaming branch from 831e849 to 06c3797 Compare March 14, 2024 20:26
@lupin012 lupin012 marked this pull request as ready for review March 14, 2024 20:56
@lupin012 lupin012 requested a review from canepat March 14, 2024 20:56
@canepat canepat changed the title rpcdaemon: Http compression no streaming rpcdaemon: add HTTP gzip compression (no streaming) Mar 16, 2024
Copy link
Member

@canepat canepat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can address suggestions in next PR

@@ -190,10 +192,11 @@ Task<void> Connection::handle_actual_request(const boost::beast::http::request<b
vary_ = req[boost::beast::http::field::vary];
origin_ = req[boost::beast::http::field::origin];
method_ = req.method();
auto encoding = req[boost::beast::http::field::accept_encoding];

auto rsp_content = co_await request_handler_.handle(req.body());
if (rsp_content) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The definition of local variable encoding should be moved inside this code branch for better readability

@@ -190,10 +192,11 @@ Task<void> Connection::handle_actual_request(const boost::beast::http::request<b
vary_ = req[boost::beast::http::field::vary];
origin_ = req[boost::beast::http::field::origin];
method_ = req.method();
auto encoding = req[boost::beast::http::field::accept_encoding];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

encoding should be declared const (next PR is OK for this and all following suggestions)


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);
co_await do_write(rsp_content->append("\n"), boost::beast::http::status::ok, !encoding.empty());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of the Accept-Encoding field should be passed to the do_write method instead of a bool. This will allow for checking within do_write which kind of content compression has been requested and accept/reject it depending on the supported compression on our side

compress_data(content, compressed_data);
} catch (const std::exception& e) {
SILK_ERROR << "Connection::compress_data exception: " << e.what();
throw;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we do really want to raise an exception here, probably we could directly return an Internal server error code or something similar

@@ -114,6 +116,8 @@ class Connection : public StreamWriter {
std::string vary_;
std::string origin_;
boost::beast::http::verb method_{boost::beast::http::verb::unknown};

char temp_compressed_buffer_[10 * 1024 * 1024];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use std::string or std::vector<char> here

@canepat canepat merged commit 552a086 into master Mar 16, 2024
5 checks passed
@canepat canepat deleted the http_compression_no_streaming branch March 16, 2024 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants