1
#pragma once
2

            
3
#include "envoy/http/header_validator.h"
4
#include "envoy/stats/scope.h"
5
#include "envoy/stats/stats_macros.h"
6

            
7
#include "source/common/common/thread.h"
8

            
9
namespace Envoy {
10
namespace Http {
11
namespace Http1 {
12

            
13
/**
14
 * All stats for the HTTP/1 codec. @see stats_macros.h
15
 */
16
#define ALL_HTTP1_CODEC_STATS(COUNTER)                                                             \
17
22597
  COUNTER(dropped_headers_with_underscores)                                                        \
18
22597
  COUNTER(metadata_not_supported_error)                                                            \
19
22597
  COUNTER(requests_rejected_with_underscores_in_headers)                                           \
20
22597
  COUNTER(response_flood)
21

            
22
/**
23
 * Wrapper struct for the HTTP/1 codec stats. @see stats_macros.h
24
 */
25
struct CodecStats : public ::Envoy::Http::HeaderValidatorStats {
26
  using AtomicPtr = Thread::AtomicPtr<CodecStats, Thread::AtomicPtrAllocMode::DeleteOnDestruct>;
27

            
28
  CodecStats(ALL_HTTP1_CODEC_STATS(GENERATE_CONSTRUCTOR_COUNTER_PARAM)...)
29
22597
      : ::Envoy::Http::HeaderValidatorStats()
30
22597
            ALL_HTTP1_CODEC_STATS(GENERATE_CONSTRUCTOR_INIT_LIST) {}
31

            
32
69674
  static CodecStats& atomicGet(AtomicPtr& ptr, Stats::Scope& scope) {
33
69674
    return *ptr.get([&scope]() -> CodecStats* {
34
22597
      return new CodecStats{ALL_HTTP1_CODEC_STATS(POOL_COUNTER_PREFIX(scope, "http1."))};
35
22597
    });
36
69674
  }
37

            
38
9
  void incDroppedHeadersWithUnderscores() override { dropped_headers_with_underscores_.inc(); }
39
5
  void incRequestsRejectedWithUnderscoresInHeaders() override {
40
5
    requests_rejected_with_underscores_in_headers_.inc();
41
5
  }
42
  // TODO(yanavlasov): add corresponding counter for H/1 codec.
43
  void incMessagingError() override {}
44

            
45
  ALL_HTTP1_CODEC_STATS(GENERATE_COUNTER_STRUCT)
46
};
47

            
48
} // namespace Http1
49
} // namespace Http
50
} // namespace Envoy