Skip to content

EntropyEngine::Networking::WebDavAdapter

VFS-to-WebDAV adapter for HTTP server integration. More…

#include <WebDavAdapter.h>

Name
std::optional< std::string >toVfsPath(const std::string & urlPath) const
Translates WebDAV URL path to VFS path.
boolhandles(const std::string & urlPath) const
Checks if URL path is under WebDAV mount prefix.
HttpResponseLitehandlePropfind(const HttpRequestLite & req, int depth =0) const
Handles PROPFIND request (resource property query).
HttpResponseLitehandleOptions(const HttpRequestLite & req) const
Handles OPTIONS request (WebDAV capability discovery).
HttpResponseLitehandleHead(const HttpRequestLite & req) const
Handles HEAD request (metadata only, no body).
HttpResponseLitehandleGet(const HttpRequestLite & req) const
Handles GET request (file content retrieval).
WebDavAdapter(std::shared_ptr< EntropyEngine::Core::IO::VirtualFileSystem > vfs, std::string mountPrefix =“/dav/“)
Constructs WebDAV adapter with VFS and mount prefix.
class EntropyEngine::Networking::WebDavAdapter;

VFS-to-WebDAV adapter for HTTP server integration.

WebDavAdapter bridges EntropyCore’s VirtualFileSystem to WebDAV (RFC 4918) semantics without binding to a specific HTTP server implementation. Provides minimal handler methods that can be wired into any HTTP library (e.g., Boost.Beast, cpp-httplib).

Features (Phase 1 MVP):

  • OPTIONS: Returns DAV compliance class (Class 1, read-only)
  • GET: Streams VFS file contents with Content-Type detection
  • HEAD: Returns file metadata without body
  • PROPFIND: Returns XML multistatus with resource properties (Depth 0/1)
  • Path mapping: Translates WebDAV URLs to VFS paths via configurable mount prefix
  • Read-only: No MKCOL/PUT/DELETE/COPY/MOVE support (future extension)

Thread Safety: All handler methods are const and thread-safe if the underlying VFS is thread-safe. Can handle concurrent requests from HTTP server threads.

Usage Pattern: Integrate with HTTP server request routing to delegate WebDAV requests to appropriate handlers based on method and path.

// Setup VFS with multiple backends
auto vfs = std::make_shared<VirtualFileSystem>();
vfs->mount("/assets", assetBackend);
vfs->mount("/config", configBackend);
// Create WebDAV adapter with /dav mount prefix
WebDavAdapter adapter(vfs, "/dav/");
// Integrate with HTTP server (pseudo-code)
httpServer.onRequest([&adapter](const auto& rawReq) -> auto {
HttpRequestLite req{
.method = rawReq.method,
.urlPath = rawReq.path,
.headers = rawReq.headers
};
if (!adapter.handles(req.urlPath)) {
return HttpResponse{404, "Not Found"};
}
HttpResponseLite resp;
if (req.method == "OPTIONS") {
resp = adapter.handleOptions(req);
} else if (req.method == "PROPFIND") {
int depth = parseDepthHeader(req.headers["Depth"]); // 0, 1, or infinity
resp = adapter.handlePropfind(req, depth);
} else if (req.method == "HEAD") {
resp = adapter.handleHead(req);
} else if (req.method == "GET") {
resp = adapter.handleGet(req);
} else {
resp.status = 405; // Method Not Allowed
}
return convertToServerResponse(resp);
});
// Client can now access VFS over WebDAV:
// GET http://localhost/dav/assets/texture.png -> reads from assetBackend
// PROPFIND http://localhost/dav/config/ Depth:1 -> lists config directory
std::optional< std::string > toVfsPath(
const std::string & urlPath
) const

Translates WebDAV URL path to VFS path.

Parameters:

  • urlPath Server-relative URL path

Return: VFS path if under mount prefix, nullopt otherwise

Strips mount prefix from URL path to produce VFS-relative path. Example: “/dav/foo/bar.txt” -> “foo/bar.txt”

bool handles(
const std::string & urlPath
) const

Checks if URL path is under WebDAV mount prefix.

Parameters:

  • urlPath Server-relative URL path (e.g., “/dav/assets/foo.bin”)

Return: true if path starts with mount prefix

HttpResponseLite handlePropfind(
const HttpRequestLite & req,
int depth =0
) const

Handles PROPFIND request (resource property query).

Parameters:

  • req HTTP request
  • depth PROPFIND depth (0 or 1, infinity not supported)

Return: 207 Multistatus with XML body, or 404 if resource not found

Returns WebDAV multistatus (207) with resource properties. Depth 0: Single resource. Depth 1: Resource + children.

HttpResponseLite handleOptions(
const HttpRequestLite & req
) const

Handles OPTIONS request (WebDAV capability discovery).

Parameters:

  • req HTTP request

Return: Response with DAV: Class 1 header and Allow: GET,HEAD,PROPFIND,OPTIONS

Returns DAV compliance class and supported methods.

HttpResponseLite handleHead(
const HttpRequestLite & req
) const

Handles HEAD request (metadata only, no body).

Parameters:

  • req HTTP request

Return: 200 OK with headers, or 404 if file not found

Returns file metadata (Content-Length, Content-Type, Last-Modified) without response body.

HttpResponseLite handleGet(
const HttpRequestLite & req
) const

Handles GET request (file content retrieval).

Parameters:

  • req HTTP request

Return: 200 OK with file body, or 404 if file not found

Reads file from VFS and returns contents with Content-Type detection.

inline explicit WebDavAdapter(
std::shared_ptr< EntropyEngine::Core::IO::VirtualFileSystem > vfs,
std::string mountPrefix ="/dav/"
)

Constructs WebDAV adapter with VFS and mount prefix.

Parameters:

  • vfs Shared VirtualFileSystem instance to expose over WebDAV
  • mountPrefix URL path prefix for WebDAV operations (e.g., “/dav/”)

Updated on 2026-01-26 at 17:14:35 -0500