proxygen
HTTPSettings.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
10 #pragma once
11 
12 #include <initializer_list>
14 #include <vector>
15 
16 /*
17  * HTTPSettings are stored in an underlying vector, presumably to limit the
18  * amount of memory required. Access various settings thus generally involves
19  * iterating over available entries. Removing entries does not require any
20  * shifts.
21  */
22 
23 namespace proxygen {
24 
26 
27 struct HTTPSetting {
29  }
30 
33 };
34 
35 class HTTPSettings {
36  public:
37  // HTTP/2 Defaults
39  : settings_({{SettingsId::HEADER_TABLE_SIZE, 4096},
41  {SettingsId::MAX_FRAME_SIZE, 16384}}) {
42  }
43  explicit HTTPSettings(
44  const std::initializer_list<SettingPair>& initialSettings) {
45  settings_.reserve(initialSettings.size());
46  // TODO: setSetting involves looping over all settings so the below actually
47  // models as O(n^2) which is pretty bad. Can't change it outright without
48  // making sure we handle duplicates (same setting id)
49  for (auto& setting : initialSettings) {
50  setSetting(setting.first, setting.second);
51  }
52  }
53  void setSetting(SettingsId id, SettingsValue val);
54  void unsetSetting(SettingsId id);
55  const HTTPSetting* getSetting(SettingsId id) const;
56  SettingsValue getSetting(SettingsId id, SettingsValue defaultVal) const;
57  // Note: this does not count disabled settings
58  std::size_t getNumSettings() const {
59  return settings_.size();
60  }
61  const std::vector<HTTPSetting>& getAllSettings() {
62  return settings_;
63  }
64  void clearSettings() {
65  settings_.clear();
66  }
67 
68  private:
69  // Returns the specified type of iterator to the setting associated with the
70  // specified id
71  std::vector<HTTPSetting>::iterator getSettingIter(SettingsId id);
72  std::vector<HTTPSetting>::const_iterator getSettingConstIter(
73  SettingsId id) const;
74 
75  // TODO: evaluate whether using a list or default initializing vector with
76  // all settings so that size == capacity (else on push_backs capacity is
77  // likely to be > size)
78  std::vector<HTTPSetting> settings_;
79 };
80 
81 using SettingsList = std::vector<HTTPSetting>;
82 
83 } // namespace proxygen
HTTPSetting(SettingsId i, SettingsValue v)
Definition: HTTPSettings.h:28
double val
Definition: String.cpp:273
std::vector< HTTPSetting > settings_
Definition: HTTPSettings.h:78
std::size_t getNumSettings() const
Definition: HTTPSettings.h:58
HTTPSettings(const std::initializer_list< SettingPair > &initialSettings)
Definition: HTTPSettings.h:43
uint64_t SettingsValue
Definition: HTTPSettings.h:25
std::vector< HTTPSetting > SettingsList
Definition: HTTPSettings.h:81
const std::vector< HTTPSetting > & getAllSettings()
Definition: HTTPSettings.h:61
SettingsValue value
Definition: HTTPSettings.h:32