Skip to content

Commit

Permalink
[filter] demuxHTTP() now supports maxMessages options
Browse files Browse the repository at this point in the history
  • Loading branch information
pajama-coder committed Sep 14, 2023
1 parent e2d9194 commit 4d23f19
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/filters/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,9 @@ Demux::Options::Options(pjs::Object *options)
Value(options, "maxHeaderSize")
.get_binary_size(max_header_size)
.check_nullable();
Value(options, "maxMessages")
.get(max_messages)
.check_nullable();
}

//
Expand Down Expand Up @@ -1290,6 +1293,7 @@ void Demux::reset() {
Decoder::chain(DemuxQueue::input());
m_request_queue.reset();
m_eos = nullptr;
m_message_count = 0;
m_http2 = false;
m_shutdown = false;
}
Expand Down Expand Up @@ -1366,7 +1370,13 @@ auto Demux::on_encode_response(ResponseHead *head) -> RequestQueue::Request* {
return nullptr;
} else {
auto req = m_request_queue.shift();
if (m_shutdown && m_request_queue.empty()) req->is_final = true;
m_message_count++;
if (
(m_options.max_messages > 0 && m_message_count >= m_options.max_messages) ||
(m_shutdown && m_request_queue.empty())
) {
req->is_final = true;
}
return req;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/filters/http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ class Demux :
struct Options : public http2::Endpoint::Options {
size_t buffer_size = DATA_CHUNK_SIZE;
size_t max_header_size = DATA_CHUNK_SIZE;
int max_messages = 0;
Options() {}
Options(pjs::Object *options);
};
Expand All @@ -314,6 +315,7 @@ class Demux :
Options m_options;
RequestQueue m_request_queue;
pjs::Ref<StreamEnd> m_eos;
int m_message_count = 0;
bool m_http2 = false;
bool m_shutdown = false;

Expand Down

0 comments on commit 4d23f19

Please sign in to comment.