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

Added stream threshold option #245

Merged
merged 1 commit into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions include/crow/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,21 @@ namespace crow
return *this;
}

/// Set a response body size (in bytes) beyond which Crow automatically streams responses (Default is 1MiB)

///
/// Any streamed response is unaffected by Crow's timer, and therefore won't timeout before a response is fully sent.
self_t& stream_threshold(size_t threshold)
{
res_stream_threshold_ = threshold;
return *this;
}

size_t& stream_threshold()
{
return res_stream_threshold_;
}

self_t& register_blueprint(Blueprint& blueprint)
{
router_.register_blueprint(blueprint);
Expand Down Expand Up @@ -398,6 +413,7 @@ namespace crow
bool validated_ = false;
std::string server_name_ = std::string("Crow/") + VERSION;
std::string bindaddr_ = "0.0.0.0";
size_t res_stream_threshold_ = 1048576;
Router router_;

#ifdef CROW_ENABLE_COMPRESSION
Expand Down
7 changes: 4 additions & 3 deletions include/crow/http_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ namespace crow
server_name_(server_name),
middlewares_(middlewares),
get_cached_date_str(get_cached_date_str_f),
timer_queue(timer_queue)
timer_queue(timer_queue),
res_stream_threshold_(handler->stream_threshold())
{
#ifdef CROW_ENABLE_DEBUG
connectionCount ++;
Expand Down Expand Up @@ -678,8 +679,6 @@ namespace crow

boost::array<char, 4096> buffer_;

const unsigned res_stream_threshold_ = 1048576;

HTTPParser<Connection> parser_;
request req_;
response res;
Expand Down Expand Up @@ -707,6 +706,8 @@ namespace crow

std::function<std::string()>& get_cached_date_str;
detail::dumb_timer_queue& timer_queue;

size_t res_stream_threshold_;
};

}