code: def _test_serve_path_via_http(
      test_fpath, use_ssl, auth, tmp_dir
  ):  # pragma: no cover
      tmp_dir = Path(tmp_dir)
      test_fpath = Path(test_fpath)
      # First verify that filesystem layer can encode this filename
      # verify first that we could encode file name in this environment
      try:
          filesysencoding = sys.getfilesystemencoding()
          test_fpath_encoded = str(test_fpath.as_posix()).encode(
              filesysencoding
          )
      except UnicodeEncodeError:  # pragma: no cover
          pytest.skip("Environment doesn't support unicode filenames")
      if (
          test_fpath_encoded.decode(filesysencoding)
          != test_fpath.as_posix()
      ):  # pragma: no cover
          pytest.skip(
              "Can't convert back/forth using %s encoding"
              % filesysencoding
          )
  
      test_fpath_full = tmp_dir / test_fpath
      test_fpath_full.parent.mkdir(parents=True, exist_ok=True)
      test_fpath_full.write_text(
          f"some txt and a randint {random.randint(1, 10)}"
      )
  
      @serve_path_via_http(tmp_dir, use_ssl=use_ssl, auth=auth)
      def test_path_and_url(path, url):
          def _urlopen(url, auth=None):
              req = Request(url)
              if auth:
                  req.add_header(
                      "Authorization",
                      b"Basic "
                      + base64.standard_b64encode(
                          "{0}:{1}".format(*auth).encode("utf-8")
                      ),
                  )
              return urlopen(req)
  
          # @serve_ should remove http_proxy from the os.environ if was present
          if not on_windows:
              assert_false("http_proxy" in os.environ)
          # get the "dir-view"
          dirurl = url + test_fpath.parent.as_posix()
          u = _urlopen(dirurl, auth)
          assert_true(u.getcode() == 200)
          html = u.read()
          # get the actual content
          file_html = (
              _urlopen(url + url_quote(test_fpath.as_posix()), auth)
              .read()
              .decode()
          )
          # verify we got the right one
          eq_(file_html, test_fpath_full.read_text())
  
          if bs4 is None:
              return
  
          # MIH is not sure what this part below is supposed to do
          # possibly some kind of internal consistency test
          soup = bs4.BeautifulSoup(html, "html.parser")
          href_links = [txt.get("href") for txt in soup.find_all("a")]
          assert_true(len(href_links) == 1)
          parsed_url = f"{dirurl}/{href_links[0]}"
          u = _urlopen(parsed_url, auth)
          html = u.read().decode()
          eq_(html, file_html)
  
      test_path_and_url()
  
imports: import base64
  import logging
  import os
  import platform
  import random
  import sys
  from glob import glob
  from os.path import basename, exists
  from os.path import join
  from unittest.mock import patch
  from urllib.parse import quote
  from urllib.request import Request, urlopen
  import pytest
  from _pytest.outcomes import Failed, Skipped
  from datalad import cfg
  from datalad.support import path
  from datalad.support.gitrepo import GitRepo
  from datalad.tests.utils_pytest import OBSCURE_FILENAMES, OBSCURE_PREFIX, assert_cwd_unchanged, assert_dict_equal, assert_false, assert_in, assert_not_in, assert_raises, assert_re_in, assert_str_equal, assert_true, eq_, get_most_obscure_supported_name, ignore_nose_capturing_stdout, known_failure_githubci_win, known_failure_windows, local_testrepo_flavors, nok_startswith, ok_, ok_broken_symlink, ok_file_has_content, ok_file_under_git, ok_generator, ok_good_symlink, ok_startswith, ok_symlink, on_windows, patch_config, probe_known_failure, rmtemp, run_under_dir, serve_path_via_http, skip_if, skip_if_no_module, skip_if_no_network, skip_if_on_windows, skip_ssh, skip_wo_symlink_capability, swallow_logs, with_tempfile, with_testsui, with_tree, without_http_proxy
  from datalad.utils import Path, chpwd, getpwd
label_desc: Use image node_id 21 for calling a global function with example usage: _test_serve_path_via_http(test_fpath, use_ssl, auth, tmp_dir) and returns: urlopen