http.get is now operational

This commit is contained in:
2022-05-06 13:16:27 -04:00
parent c41d0522df
commit 0ee4167772
7 changed files with 174 additions and 98 deletions

View File

@@ -25,6 +25,7 @@ public:
LuaConsole console_;
ClientVector clients_;
PrintChanneler print_channeler_;
HttpClientChannelMap http_client_channels_;
int64_t admin_id_;
Gui gui_;
@@ -201,6 +202,41 @@ public:
while (handle_invocation(client));
}
util::remove_nullptrs(clients_);
// Look for new outgoing HTTP client requests.
for (const auto &pair : master_->http_requests()) {
const HttpClientRequest &request = pair.second;
HttpClientChannel &channel = http_client_channels_[request.request_id()];
if (channel.channel_ == nullptr) {
channel.channel_ = new_outgoing_channel(request.target());
channel.parsed_bytes_ = 0;
request.send(channel.channel_->out());
}
}
// Maintain existing outgoing HTTP client requests.
HttpClientResponseVec http_responses;
for (auto &pair : http_client_channels_) {
HttpClientChannel &htchan = pair.second;
Channel &channel = *htchan.channel_;
if (channel.closed() || (channel.in()->fill() > htchan.parsed_bytes_)) {
HttpClientResponse response;
if (!channel.error().empty()) {
response.fail(503, util::ss("Service Unavailable: ", channel.error()));
} else {
htchan.parsed_bytes_ = channel.in()->fill();
response.parse(channel.in(), channel.closed());
}
if (response.complete()) {
response.set_request_id(pair.first);
http_responses.push_back(response);
}
}
}
for (const HttpClientResponse &response : http_responses) {
http_client_channels_.erase(response.request_id());
}
master_->http_responses(http_responses);
}
};