func()

in internal/serving/disk/reader.go [91:136]


func (reader *Reader) tryFile(h serving.Handler) bool {
	defer slowlogs.Recorder(h.Request.Context(), "reader.tryFile")()

	ctx := h.Request.Context()

	root, served := reader.root(h)
	if root == nil {
		return served
	}

	fullPath, err := reader.resolvePath(ctx, root, h.SubPath)

	request := h.Request
	urlPath := request.URL.Path

	var locationDirError *locationDirectoryError
	if errors.As(err, &locationDirError) {
		if endsWithSlash(urlPath) {
			fullPath, err = reader.resolvePath(ctx, root, h.SubPath, "index.html")
		} else {
			http.Redirect(h.Writer, h.Request, redirectPath(h.Request), http.StatusFound)
			return true
		}
	}

	var locationFileError *locationFileNoExtensionError
	if errors.As(err, &locationFileError) {
		fullPath, err = reader.resolvePath(ctx, root, strings.TrimSuffix(h.SubPath, "/")+".html")
	}

	if err != nil {
		// We assume that this is mostly missing file type of the error
		// and additional handlers should try to process the request
		return false
	}

	// Serve status of `_redirects` under `_redirects`
	// We check if the final resolved path is `_redirects` after symlink traversal
	if fullPath == redirects.ConfigFile {
		r := redirects.ParseRedirects(ctx, root)
		reader.serveRedirectsStatus(h, r)
		return true
	}

	return reader.serveFile(ctx, h.Writer, h.Request, root, fullPath, h.LookupPath.SHA256, h.LookupPath.HasAccessControl)
}