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
89
AsyncClientRequestTracker::~AsyncClientRequestTracker() {
9
89
  for (auto* active_request : active_requests_) {
10
4
    active_request->cancel();
11
4
  }
12
89
}
13

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

            
19
43
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
43
  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
43
  if (it != active_requests_.end()) {
27
38
    active_requests_.erase(it);
28
38
  }
29
43
}
30

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