| 176 | } |
| 177 | |
| 178 | Result 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 |