code: public static @Nullable Resource getContentResourceOrParent(@NotNull HttpServletRequest request) {
      String contentPath = getContentPath(request);
      return getContentResourceOrParentFromPath((SlingHttpServletRequest)request, contentPath);
    }
docs: Get current content resource
  If it does not exist, go up the content path and return the first resource that exists.
  @param request Request
  @return Current content resource or the first existing parent/ancestor.