| 139 | } |
| 140 | |
| 141 | Result HttpRouter::match(HttpParser::Method method, StringSpan requestTarget, Span<HttpRouteParam> params, |
| 142 | HttpRouteMatch& match) const |
| 143 | { |
| 144 | match = {}; |
| 145 | |
| 146 | HttpRequestTargetView target; |
| 147 | SC_TRY(target.parse(requestTarget)); |
| 148 | const StringSpan requestPath = target.path; |
| 149 | bool pathMatched = false; |
| 150 | for (const HttpRoute& route : routes) |
| 151 | { |
| 152 | size_t numParams = 0; |
| 153 | const HttpRouteMatchStatus status = |
| 154 | HttpRouterInternal::matchPath(route.pathPattern, requestPath, params, numParams); |
| 155 | if (status == HttpRouteMatchStatus::TooManyParams) |
| 156 | { |
| 157 | match.status = status; |
| 158 | return Result(true); |
| 159 | } |
| 160 | if (status != HttpRouteMatchStatus::Matched) |
| 161 | { |
| 162 | continue; |
| 163 | } |
| 164 | pathMatched = true; |
| 165 | if (route.method == method) |
| 166 | { |
| 167 | match.status = HttpRouteMatchStatus::Matched; |
| 168 | match.route = &route; |
| 169 | match.numParams = numParams; |
| 170 | return Result(true); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | match.status = pathMatched ? HttpRouteMatchStatus::MethodNotAllowed : HttpRouteMatchStatus::NotFound; |
| 175 | return Result(true); |
| 176 | } |
| 177 | |
| 178 | Result HttpRouter::formatAllowHeader(StringSpan requestTarget, Span<char> storage, StringSpan& allow) const |
| 179 | { |