1
#include "source/common/http/async_client_utility.h"
2

            
3
#include "source/common/common/assert.h"
4

            
5
namespace Envoy {
6
namespace Http {
7

            
8
86
AsyncClientRequestTracker::~AsyncClientRequestTracker() {
9
86
  for (auto* active_request : active_requests_) {
10
4
    active_request->cancel();
11
4
  }
12
86
}
13

            
14
39
void AsyncClientRequestTracker::add(AsyncClient::Request& request) {
15
39
  ASSERT(active_requests_.find(&request) == active_requests_.end(), "request is already tracked.");
16
39
  active_requests_.insert(&request);
17
39
}
18

            
19
40
void AsyncClientRequestTracker::remove(const AsyncClient::Request& request) {
20
  // Notice that use of "const_cast" here is motivated by keeping API convenient for client code.
21
  // In the context where remove() will be typically called, request.cancel() is no longer
22
  // desirable and therefore get prevented by means of "const" modifier.
23
40
  auto it = active_requests_.find(const_cast<AsyncClient::Request*>(&request));
24
  // Support a use case where request callbacks might get called prior to a request handle
25
  // is returned from AsyncClient::send().
26
40
  if (it != active_requests_.end()) {
27
35
    active_requests_.erase(it);
28
35
  }
29
40
}
30

            
31
} // namespace Http
32
} // namespace Envoy