/// Resolve the request path by trying to find the file in the given root.
///
/// This root may be absolute or relative. The request path is mapped onto the filesystem by
/// appending it to the root path. If the filesystem path corresponds to a regular file, the
/// service will attempt to serve it. Otherwise, if the path corresponds to a directory containing
/// an `index.html`, the service will attempt to serve that instead.
///
/// The returned future may error for unexpected IO errors, passing on the `std::io::Error`.
/// Certain expected IO errors are handled, though, and simply reflected in the result. These are
/// `NotFound` and `PermissionDenied`.
///
/// Note that, unlike `resolve`, it is up to the caller to check the request method.
Resolve the request path by trying to find the file in the given root.
This root may be absolute or relative. The request path is mapped onto the filesystem by
appending it to the root path. If the filesystem path corresponds to a regular file, the
service will attempt to serve it. Otherwise, if the path corresponds to a directory containing
an `index.html`, the service will attempt to serve that instead.

The returned future may error for unexpected IO errors, passing on the `std::io::Error`.
Certain expected IO errors are handled, though, and simply reflected in the result.

Note that, unlike `resolve`, it is up to the caller to check the request method.
Resolve the request path by trying to find the file in the given root . This root may be absolute or relative . The request path is mapped onto the filesystem by appending it to the root path . If the filesystem path corresponds to a regular file the service will attempt to serve it . Otherwise if the path corresponds to a directory containing an ` index . html ` the service will attempt to serve that instead . The returned future may error for unexpected IO errors passing on the ` std :: io :: Error ` . Certain expected IO errors are handled though and simply reflected in the result . Note that unlike ` resolve ` it is up to the caller to check the request method .
pub async fn resolve_path(
    root: impl Into<PathBuf>,
    request_path: &str,
) -> Result<ResolveResult, IoError> {
    let RequestedPath {
        mut full_path,
        is_dir_request,
    } = RequestedPath::resolve(root, request_path);
    let (file, metadata) = match open_with_metadata(&full_path).await {
        Ok(pair) => pair,
        Err(err) => return map_open_err(err),
    };
    // The resolved `full_path` doesn't contain the trailing slash anymore, so we may
    // have opened a file for a directory request, which we treat as 'not found'.
    if is_dir_request && !metadata.is_dir() {
        return Ok(ResolveResult::NotFound);
    }
    // We may have opened a directory for a file request, in which case we redirect.
    if !is_dir_request && metadata.is_dir() {
        return Ok(ResolveResult::IsDirectory);
    }
    // If not a directory, serve this file.
    if !is_dir_request {
        let mime = MimeGuess::from_path(&full_path).first_or_octet_stream();
        return Ok(ResolveResult::Found(file, metadata, mime));
    }
    // Resolve the directory index.
    full_path.push("index.html");
    let (file, metadata) = match open_with_metadata(&full_path).await {
        Ok(pair) => pair,
        Err(err) => return map_open_err(err),
    };
    // The directory index cannot itself be a directory.
    if metadata.is_dir() {
        return Ok(ResolveResult::NotFound);
    }
    // Serve this file.
    let mime = MimeGuess::from_path(full_path).first_or_octet_stream();
    Ok(ResolveResult::Found(file, metadata, mime))
}
pub async fn resolve_path ( root : impl Into < PathBuf > , request_path : & str , ) -> Result < ResolveResult , IoError > { let RequestedPath { mut full_path , is_dir_request , } = RequestedPath :: resolve ( root , request_path ) ; let ( file , metadata ) = match open_with_metadata ( & full_path ) . await { Ok ( pair ) => pair , Err ( err ) => return map_open_err ( err ) , } ; // The resolved `full_path` doesn't contain the trailing slash anymore, so we may // have opened a file for a directory request, which we treat as 'not found'. if is_dir_request && ! metadata . is_dir ( ) { return Ok ( ResolveResult :: NotFound ) ; } // We may have opened a directory for a file request, in which case we redirect. if ! is_dir_request && metadata . is_dir ( ) { return Ok ( ResolveResult :: IsDirectory ) ; } // If not a directory, serve this file. if ! is_dir_request { let mime = MimeGuess :: from_path ( & full_path ) . first_or_octet_stream ( ) ; return Ok ( ResolveResult :: Found ( file , metadata , mime ) ) ; } // Resolve the directory index. full_path . push ( " " ) ; let ( file , metadata ) = match open_with_metadata ( & full_path ) . await { Ok ( pair ) => pair , Err ( err ) => return map_open_err ( err ) , } ; // The directory index cannot itself be a directory. if metadata . is_dir ( ) { return Ok ( ResolveResult :: NotFound ) ; } // Serve this file. let mime = MimeGuess :: from_path ( full_path ) . first_or_octet_stream ( ) ; Ok ( ResolveResult :: Found ( file , metadata , mime ) ) }
Resolve the request path by trying to find the file in the given root.
Resolve the request path by trying to find the file in the given root .
root
impl Into<PathBuf>
request_path
&str