Factorize the code for h2o_find_handler
@@ -156,7 +156,7 @@ static void call_handlers(h2o_req_t *req, h2o_handler_t **handler)
h2o_send_error_404(req, "File Not Found", "not found", 0);
}
-static void process_hosted_request(h2o_req_t *req, h2o_hostconf_t *hostconf)
+static void setup_pathconf(h2o_req_t *req, h2o_hostconf_t *hostconf)
{
h2o_pathconf_t *selected_pathconf = &hostconf->fallback_path;
size_t i;
@@ -173,30 +173,21 @@ static void process_hosted_request(h2o_req_t *req, h2o_hostconf_t *hostconf)
}
}
h2o_req_bind_conf(req, hostconf, selected_pathconf);
+}
+static void process_hosted_request(h2o_req_t *req, h2o_hostconf_t *hostconf)
+{
+ setup_pathconf(req, hostconf);
call_handlers(req, req->pathconf->handlers.entries);
}
static h2o_handler_t *find_handler(h2o_req_t *req, h2o_hostconf_t *hostconf)
{
- h2o_pathconf_t *selected_pathconf = &hostconf->fallback_path;
- size_t i;
-
- /* setup pathconf, or redirect to "path/" */
- for (i = 0; i != hostconf->paths.size; ++i) {
- h2o_pathconf_t *candidate = hostconf->paths.entries + i;
- if (req->path_normalized.len >= candidate->path.len &&
- memcmp(req->path_normalized.base, candidate->path.base, candidate->path.len) == 0 &&
- (candidate->path.base[candidate->path.len - 1] == '/' || req->path_normalized.len == candidate->path.len ||
- req->path_normalized.base[candidate->path.len] == '/')) {
- selected_pathconf = candidate;
- break;
- }
- }
- h2o_req_bind_conf(req, hostconf, selected_pathconf);
+ h2o_handler_t **handler, **end;
- h2o_handler_t **handler = req->pathconf->handlers.entries;
- h2o_handler_t **end = req->pathconf->handlers.entries + req->pathconf->handlers.size;
+ setup_pathconf(req, hostconf);
+ handler = req->pathconf->handlers.entries;
+ end = req->pathconf->handlers.entries + req->pathconf->handlers.size;
for (; handler != end; ++handler)
return *handler;
