Skip to content

Documentation / base / PythonHttpServerReader

Class: PythonHttpServerReader

Defined in: libs/base/src/vfs/readers/python_httpserver_reader.ts:22

Directory reader for Python's built-in http.server (and similar) HTML directory listings.

Remarks

  • Detects pages served by Python's http.server by scanning the <title> or <h1> tags.
  • Parses <ul><li><a> (default Python layout) and falls back to plain <a> links.
  • Skips parent directory entries (../), external links, and anchors.
  • Attempts to extract file size and modification date from the link's surrounding text.
  • Normalizes resolved paths via the provided HttpDirectoryReaderContext.

Limitations:

  • Parsing depends on the server's HTML structure; non-standard variants may not be fully parsed.
  • Size and date extraction are best-effort and may be unavailable in some cases.

Implements

Constructors

Constructor

new PythonHttpServerReader(): PythonHttpServerReader

Returns

PythonHttpServerReader

Properties

name

readonly name: "python-http-server" = 'python-http-server'

Defined in: libs/base/src/vfs/readers/python_httpserver_reader.ts:23

Human-readable name of this reader implementation (for diagnostics/logging).

Implementation of

HttpDirectoryReader.name

Methods

canHandle()

canHandle(dirPath, ctx): Promise<boolean>

Defined in: libs/base/src/vfs/readers/python_httpserver_reader.ts:25

Optional probe that indicates whether this reader can handle the given directory.

Typical strategies:

  • Check for a known index file (e.g., "index.json")
  • HEAD/GET and inspect headers/content patterns

If omitted, the host may assume the reader can handle all directories.

Parameters

dirPath

string

Normalized directory path (typically ends with "/").

ctx

HttpDirectoryReaderContext

Context utilities for fetching and path handling.

Returns

Promise<boolean>

true if supported, otherwise false. May return a promise.

Implementation of

HttpDirectoryReader.canHandle


readOnce()

readOnce(dirPath, ctx): Promise<FileMetadata[]>

Defined in: libs/base/src/vfs/readers/python_httpserver_reader.ts:39

Performs a single-pass listing of the directory at dirPath.

Requirements:

  • Return only direct children of dirPath (non-recursive).
  • Populate FileMetadata fields as accurately as possible (name, path, type, size, timestamps, mimeType).
  • Use ctx.normalizePath/ctx.joinPath to build stable path fields.

Error handling:

  • Throw on unrecoverable errors (the host VFS may fall back to other readers).
  • Return an empty array if the directory is valid but contains no entries.

Parameters

dirPath

string

Normalized directory path to read (typically ends with "/").

ctx

HttpDirectoryReaderContext

Context utilities for network and path operations.

Returns

Promise<FileMetadata[]>

A promise resolving to a flat list of file/directory metadata.

Implementation of

HttpDirectoryReader.readOnce

Released under the MIT License.