MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / Read

Method Read

src/bitcoin-cli.cpp:102–129  ·  view source on GitHub ↗

Named Read() in HTTPHeaders (see PR #35182).

Source from the content-addressed store, hash-verified

100
101// Named Read() in HTTPHeaders (see PR #35182).
102void HTTPResponseHeaders::Read(util::LineReader& reader)
103{
104 // Headers https://httpwg.org/specs/rfc9110.html#rfc.section.6.3
105 // A sequence of Field Lines https://httpwg.org/specs/rfc9110.html#rfc.section.5.2
106 while (auto maybe_line = reader.ReadLine()) {
107 const std::string_view line = *maybe_line;
108
109 // An empty line indicates end of the headers section https://www.rfc-editor.org/rfc/rfc2616#section-4
110 if (line.empty()) return;
111
112 // Header line must have at least one ":"
113 // keys are not allowed to have delimiters like ":" but values are
114 // https://httpwg.org/specs/rfc9110.html#rfc.section.5.6.2
115 const size_t pos{line.find(':')};
116 if (pos == std::string::npos) throw HTTPError{"Header missing colon (:)"};
117
118 // Whitespace is optional
119 std::string key = util::TrimString(std::string_view(line).substr(0, pos));
120 std::string value = util::TrimString(std::string_view(line).substr(pos + 1));
121
122 // Header keys are Field Names: https://httpwg.org/specs/rfc9110.html#fields.names
123 // which consist of "tokens": https://httpwg.org/specs/rfc9110.html#rfc.section.5.6.2
124 // that can not be empty.
125 if (key.empty()) throw HTTPError{"Empty header name"};
126
127 m_headers.emplace_back(std::move(key), std::move(value));
128 }
129}
130
131std::optional<std::string> HTTPResponseHeaders::FindFirst(std::string_view key) const
132{

Callers 1

ReadResponseMethod · 0.45

Calls 5

TrimStringFunction · 0.85
ReadLineMethod · 0.80
findMethod · 0.80
emptyMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected