MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / formatAllowHeader

Method formatAllowHeader

Libraries/Http/HttpRouter.cpp:178–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

176}
177
178Result HttpRouter::formatAllowHeader(StringSpan requestTarget, Span<char> storage, StringSpan& allow) const
179{
180 allow = {};
181
182 HttpParser::Method methods[7];
183 size_t numMethods = 0;
184 HttpRouteParam params[8];
185 HttpRequestTargetView target;
186 SC_TRY(target.parse(requestTarget));
187 const StringSpan requestPath = target.path;
188 for (const HttpRoute& route : routes)
189 {
190 size_t numParams = 0;
191 const HttpRouteMatchStatus status =
192 HttpRouterInternal::matchPath(route.pathPattern, requestPath, params, numParams);
193 if (status == HttpRouteMatchStatus::Matched and
194 not HttpRouterInternal::containsMethod({methods, numMethods}, numMethods, route.method))
195 {
196 methods[numMethods++] = route.method;
197 }
198 }
199
200 size_t offset = 0;
201 for (size_t idx = 0; idx < numMethods; ++idx)
202 {
203 if (idx > 0)
204 {
205 SC_TRY_MSG(HttpRouterInternal::append(storage, offset, ", "),
206 "HttpRouter Allow output buffer is too small");
207 }
208 SC_TRY_MSG(HttpRouterInternal::append(storage, offset, HttpRouterInternal::methodName(methods[idx])),
209 "HttpRouter Allow output buffer is too small");
210 }
211 allow = {{storage.data(), offset}, false, StringEncoding::Ascii};
212 return Result(true);
213}
214
215} // namespace SC

Callers 3

routeMatchingMethod · 0.80
diagnosticMessagesMethod · 0.80
onRequestMethod · 0.80

Calls 4

appendFunction · 0.50
ResultClass · 0.50
parseMethod · 0.45
dataMethod · 0.45

Tested by 2

routeMatchingMethod · 0.64
diagnosticMessagesMethod · 0.64