diff --git a/repo.c b/repo.c index b38b80c..5ac198c 100644 --- a/repo.c +++ b/repo.c @@ -1025,10 +1025,30 @@ static dav_error *deliver_directory( apr_bucket_brigade *bb = apr_brigade_create(pool, output->c->bucket_alloc); apr_bucket *bkt; + // Collection URIs must end with a slash to make relative links work. + // Normally, web servers redirect clients to `path + '/'` if it's missing, + // but mod_dav does not expect us to return a redirect status code (it + // works, but results in mod_dav error messages). + // + // As an alternative solution, we supply a HTML tag containing the + // correct collection path (with appended '/' if necessary). This is then + // used by the browser as a base URI for all relative links. + // + bool uri_ends_with_slash = false; + { size_t uri_length = strlen(resource->info->relative_uri); + if (uri_length && resource->info->relative_uri[uri_length-1] == '/') + uri_ends_with_slash = true; } + // Send start of HTML document. - apr_brigade_printf(bb, NULL, NULL, "\n\nIndex of %s on %s\n", + apr_brigade_printf(bb, NULL, NULL, + "\n\n\n" + "Index of %s on %s\n" + "\n" + "\n", ap_escape_html(pool, resource->info->relative_uri), - ap_escape_html(pool, resource->info->conf->rods_zone)); + ap_escape_html(pool, resource->info->conf->rods_zone), + ap_escape_html(pool, ap_escape_uri(pool, resource->info->relative_uri)), + uri_ends_with_slash ? "" : "/"); // Append a slash to fix relative links on this page. apr_brigade_printf(bb, NULL, NULL, "\n\n" "