feat: expose extensible filesystem projection engine

Separate pinned Linux backend, typed composition, coherent principal policy views and standard HTTP adapter. Refresh validators inside serialized execution and preserve default listener and effect boundaries. Linux/adapter and real-listener regressions pass.
This commit is contained in:
2026-10-06 18:12:05 +09:00
parent ea49cb0586
commit b196047b57
7 changed files with 1731 additions and 539 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ name = "wip-fs-server"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
description = "Request-time filesystem projection server for WIP over HTTP"
description = "Extensible request-time filesystem projection library and WIP over HTTP server"
license.workspace = true
repository.workspace = true
readme = "README.md"
+146
View File
@@ -0,0 +1,146 @@
//! Reusable default Linux composition; no listener or authentication dependency.
use crate::engine::{BackendEntry, Composition, DefaultPolicy, EntryKind, Projection};
use crate::interfaces::{
FileRead, FileReadDefinition, FileWrite, FileWriteDefinition, SymlinkInspect,
SymlinkInspectDefinition,
};
use crate::projection::{LinuxBackend, LinuxEntry};
use crate::{AccessMode, ResourceLimits};
use wip_host::{
ExecutionContext, HostError, InterfaceRef, InterfaceRegistry, PublishedObject,
RegisteredInterface, RegistrationError, Validator, WipObject,
};
use wip_interface as wip;
/// Registered built-in interfaces, usable by external compositions and Objects.
pub struct DefaultInterfaces {
/// Bounded regular-file reads.
pub read: RegisteredInterface<FileReadDefinition>,
/// No-follow link inspection.
pub symlink: RegisteredInterface<SymlinkInspectDefinition>,
/// Validator-protected replacement.
pub write: RegisteredInterface<FileWriteDefinition>,
}
impl DefaultInterfaces {
/// Register reusable default descriptors without publishing any objects.
pub fn register(registry: &mut InterfaceRegistry) -> Result<Self, RegistrationError> {
Ok(Self {
read: registry.register(FileReadDefinition, None)?,
symlink: registry.register(SymlinkInspectDefinition, None)?,
write: registry.register(FileWriteDefinition, None)?,
})
}
}
/// Default capability-aware Linux publication, independent of HTTP.
pub struct DefaultComposition {
interfaces: DefaultInterfaces,
}
impl DefaultComposition {
/// Use previously registered built-in interface tokens.
pub fn new(interfaces: DefaultInterfaces) -> Self {
Self { interfaces }
}
}
/// Request-scoped default Object; external Objects may instead wrap `LinuxEntry`.
pub struct DefaultObject {
entry: LinuxEntry,
write: InterfaceRef,
}
impl DefaultObject {
/// The pinned, bounded capability used by every operation on this Object.
pub fn entry(&self) -> &LinuxEntry {
&self.entry
}
}
impl WipObject for DefaultObject {
fn name(&self) -> &str {
self.entry.name()
}
fn description(&self) -> Option<&str> {
self.entry.description()
}
fn reference(&self) -> Option<&str> {
self.entry.reference()
}
fn validator(&self) -> Option<&Validator> {
self.entry.validator()
}
fn requires_validator(&self, interface: &InterfaceRef, operation: &str) -> bool {
interface == &self.write && operation == "replace"
}
}
impl FileRead for DefaultObject {
fn read(&self, offset: Option<u64>, length: Option<u64>) -> wip::OperationResult<wip::Bytes> {
self.entry.read(offset, length)
}
}
impl SymlinkInspect for DefaultObject {
fn read_link(&self) -> wip::OperationResult<wip::Bytes> {
self.entry.read_link()
}
}
impl FileWrite for DefaultObject {
fn replace(&self, contents: wip::Bytes) -> wip::OperationResult<()> {
self.entry.replace(contents)
}
}
impl Composition<LinuxEntry> for DefaultComposition {
type Object = DefaultObject;
fn publish(
&self,
entry: LinuxEntry,
_: &ExecutionContext,
) -> Result<PublishedObject<Self::Object>, HostError> {
let kind = entry.kind();
let writable = entry.access_mode() == AccessMode::ReadWrite;
let mut publication = PublishedObject::new(DefaultObject {
entry,
write: self.interfaces.write.reference().clone(),
});
match kind {
EntryKind::Regular => {
publication = publication
.expose(&self.interfaces.read)
.map_err(publication_error)?;
if writable {
publication = publication
.expose(&self.interfaces.write)
.map_err(publication_error)?;
}
}
EntryKind::Symlink => {
publication = publication
.expose(&self.interfaces.symlink)
.map_err(publication_error)?;
}
EntryKind::Directory | EntryKind::Unsupported => {}
}
Ok(publication)
}
}
fn publication_error(_: wip_host::PublicationError) -> HostError {
HostError::internal(
"default publication failed",
wip_host::EffectGuarantee::NotCommitted,
)
}
/// Construct the secure-by-default Linux engine without binding a listener.
pub fn default_projection(
root: &std::path::Path,
access: AccessMode,
limits: ResourceLimits,
) -> Result<Projection<LinuxBackend, DefaultComposition, DefaultPolicy>, std::io::Error> {
let backend = LinuxBackend::open(root, access, limits)?;
let mut registry = InterfaceRegistry::new();
let interfaces = DefaultInterfaces::register(&mut registry).map_err(std::io::Error::other)?;
Ok(Projection::new(
backend,
registry,
DefaultComposition::new(interfaces),
DefaultPolicy,
limits,
))
}
+594
View File
@@ -0,0 +1,594 @@
//! Transport-independent projection, publication, and principal view boundaries.
use crate::ResourceLimits;
use wip_host::{
EffectGuarantee, ExecutionContext, HostError, InterfaceRef, InterfaceRegistry, ObjectProvider,
OperationAttempt, ProviderResult, PublishedObject, WipObject,
};
use wip_protocol::{
FetchInterfaceRequest, FetchInterfaceResponse, ObjectObservation, ObserveRequest,
ObserveResponse, ProtocolError, ProtocolErrorCode,
};
/// Portable entry classification; capabilities must not be inferred from kind alone.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EntryKind {
/// Container whose children can be enumerated.
Directory,
/// Regular data entry.
Regular,
/// Link itself, never implicitly followed.
Symlink,
/// Metadata-only entry unless the composition supplies a capability.
Unsupported,
}
/// A root-confined, request-time capability, not a path to resolve again.
///
/// Metadata must be safe for public exposure. Validators bind both identity and
/// protected state. Cloning must retain the same target rather than re-resolve it.
pub trait BackendEntry: WipObject + Clone {
/// Classification for observation and publication selection.
fn kind(&self) -> EntryKind;
}
/// Trusted backend boundary. Implementations need not use POSIX semantics.
///
/// Resolve and enumerate pinned capabilities within the configured root. Enforce
/// context cancellation, deadlines and work budgets during backend work. Do not
/// advertise capabilities the backend cannot guarantee. Errors must not include
/// backend paths, credentials or hidden metadata.
///
/// `execute` must retain the same target and serialize validator observation,
/// publication, validation, typed dispatch and commit/rollback. Refresh entry
/// validators *inside* the boundary before invoking the callback, and return the
/// committed post-operation validator on success. Never upgrade an unknown
/// outcome except after confirmed rollback. Locks only protect against actors
/// participating in that locking protocol; document any external-writer limits.
pub trait FilesystemBackend {
/// Stable capability supplied to the composition.
type Entry: BackendEntry;
/// Resolve a canonical WIP path without escaping the configured root.
fn resolve(&self, context: &ExecutionContext, path: &str) -> ProviderResult<Self::Entry>;
/// Enumerate direct children, at most `maximum`; excess must fail, not truncate.
fn children(
&self,
context: &ExecutionContext,
entry: &Self::Entry,
maximum: usize,
) -> Result<Vec<Self::Entry>, HostError>;
/// Execute against this already-resolved target within an atomic boundary.
fn execute(
&self,
context: &ExecutionContext,
entry: Self::Entry,
operation: impl FnOnce(Self::Entry) -> OperationAttempt,
) -> ProviderResult<OperationAttempt>;
}
/// Typed publication extension point, implementable on an external crate's type.
///
/// Use `InterfaceRegistry::register` and `PublishedObject::expose` with generated
/// definitions. An external local Object can wrap the entry and implement any
/// number of interfaces, avoiding orphan rules. Its `WipObject` implementation
/// declares validator requirements per qualified operation. Operation failures
/// declare their own `EffectGuarantee`, not a fixed read/write classification.
pub trait Composition<E: BackendEntry> {
/// Local typed operation implementation and safe public metadata.
type Object: WipObject;
/// Build a request-scoped publication using this exact capability/context.
///
/// Publication and policy hooks must be side-effect-free with respect to the
/// backend. A publication failure is a pre-dispatch rejection, never a
/// started Operation. Delegate metadata/validators to the boundary snapshot.
fn publish(
&self,
entry: E,
context: &ExecutionContext,
) -> Result<PublishedObject<Self::Object>, HostError>;
}
/// Principal-specific view policy, independent of authentication transport.
///
/// Keep decisions deterministic and stable within an effective Worldspace view.
/// A changed policy requires a new view/reference lifetime (or interface
/// validators). Operation visibility is interface-wide within a view so every
/// published reference has exactly the descriptor returned by fetch. Entry-
/// specific differences should select different registered interfaces. Hooks
/// cannot add implementations, metadata, or raw paths to a publication.
pub trait ProjectionPolicy<E: BackendEntry, O: WipObject> {
/// Opaque deployment-established principal/request identity.
type Principal;
/// Whether the entry is visible. Invisible ancestors hide their whole subtree.
fn object_visible(&self, principal: &Self::Principal, entry: &E) -> bool;
/// Whether an interface descriptor may be fetched in this view.
fn interface_visible(&self, _principal: &Self::Principal, _interface: &InterfaceRef) -> bool {
true
}
/// Select/order a subset of implemented interfaces; defaults to all.
fn interfaces(
&self,
_principal: &Self::Principal,
_entry: &E,
available: &[InterfaceRef],
) -> Vec<InterfaceRef> {
available.to_vec()
}
/// Whether an operation is present in this view's descriptor and dispatch.
fn operation_visible(
&self,
_principal: &Self::Principal,
_interface: &InterfaceRef,
_operation: &str,
) -> bool {
true
}
/// Execution permission for a visible operation, after canonical preconditions.
fn authorize(
&self,
_principal: &Self::Principal,
_object: &O,
_interface: &InterfaceRef,
_operation: &str,
) -> bool {
true
}
}
/// No authentication assumption: all configured objects/operations are visible.
pub struct DefaultPolicy;
impl<E: BackendEntry, O: WipObject> ProjectionPolicy<E, O> for DefaultPolicy {
type Principal = ();
fn object_visible(&self, _: &(), _: &E) -> bool {
true
}
}
/// Canonical request-time engine, independent of HTTP and Linux.
pub struct Projection<B, C, P> {
backend: B,
registry: InterfaceRegistry,
composition: C,
policy: P,
limits: ResourceLimits,
}
impl<B, C, P> Projection<B, C, P>
where
B: FilesystemBackend,
C: Composition<B::Entry>,
P: ProjectionPolicy<B::Entry, C::Object>,
{
/// Assemble trusted components. The registry must contain all exposed tokens.
pub fn new(
backend: B,
registry: InterfaceRegistry,
composition: C,
policy: P,
limits: ResourceLimits,
) -> Self {
Self {
backend,
registry,
composition,
policy,
limits,
}
}
/// Backend access for trusted composition/configuration, never serialized.
pub fn backend(&self) -> &B {
&self.backend
}
/// Borrow one effective principal view for observation, fetch and dispatch.
pub fn view<'a>(&'a self, principal: &'a P::Principal) -> ProjectionView<'a, B, C, P> {
ProjectionView {
projection: self,
principal,
}
}
}
/// A coherent principal view implementing canonical typed host dispatch.
pub struct ProjectionView<'a, B, C, P>
where
B: FilesystemBackend,
C: Composition<B::Entry>,
P: ProjectionPolicy<B::Entry, C::Object>,
{
projection: &'a Projection<B, C, P>,
principal: &'a P::Principal,
}
impl<B, C, P> ProjectionView<'_, B, C, P>
where
B: FilesystemBackend,
C: Composition<B::Entry>,
P: ProjectionPolicy<B::Entry, C::Object>,
{
fn resolve(&self, context: &ExecutionContext, path: &str) -> ProviderResult<B::Entry> {
if let Err(error) = preflight(context) {
return ProviderResult::Failure(error);
}
if wip_protocol::validate_path(path).is_err() {
return ProviderResult::NotFound;
}
// Check ancestors as well: guessing a descendant cannot bypass hidden parents.
let mut end = 1;
loop {
let prefix = if end == 1 { "/" } else { &path[..end] };
let entry = match self.projection.backend.resolve(context, prefix) {
ProviderResult::Found(entry) => entry,
ProviderResult::NotFound => return ProviderResult::NotFound,
ProviderResult::Failure(error) => return ProviderResult::Failure(error),
};
if !self
.projection
.policy
.object_visible(self.principal, &entry)
{
return ProviderResult::NotFound;
}
if prefix == path {
return ProviderResult::Found(entry);
}
let start = if end == 1 { 1 } else { end + 1 };
end = path[start..]
.find('/')
.map_or(path.len(), |index| start + index);
}
}
fn publication(
&self,
entry: B::Entry,
context: &ExecutionContext,
) -> Result<PublishedObject<C::Object>, HostError> {
let publication = self
.projection
.composition
.publish(entry.clone(), context)?;
let available = publication
.protocol_object()
.interfaces
.iter()
.map(|reference| {
self.projection
.registry
.resolve(reference)
.ok_or_else(internal)
})
.collect::<Result<Vec<_>, _>>()?;
let mut selected = self
.projection
.policy
.interfaces(self.principal, &entry, &available);
selected.retain(|reference| {
self.projection
.policy
.interface_visible(self.principal, reference)
});
publication
.project(&selected, |reference, operation| {
self.projection
.policy
.operation_visible(self.principal, reference, operation)
})
.map_err(|_| internal())
}
/// Retrieve the descriptor with precisely this principal's visible operations.
pub fn fetch_interface(
&self,
request: &FetchInterfaceRequest,
) -> Result<FetchInterfaceResponse, ProtocolError> {
read_boundary(|| self.fetch_interface_inner(request))
}
fn fetch_interface_inner(
&self,
request: &FetchInterfaceRequest,
) -> Result<FetchInterfaceResponse, ProtocolError> {
let observation = self
.projection
.registry
.fetch_interface(&request.interface)?;
if !self
.projection
.policy
.interface_visible(self.principal, &observation.reference)
{
return Err(protocol(
ProtocolErrorCode::InterfaceNotFound,
"interface is not published",
));
}
let reference = observation.reference.clone();
observation
.project_operations(|operation| {
self.projection
.policy
.operation_visible(self.principal, &reference, operation)
})
.protocol_response()
}
/// Observe a complete bounded tree, omitting invisible children and subtrees.
pub fn observe(
&self,
context: &ExecutionContext,
request: &ObserveRequest,
) -> Result<ObserveResponse, ProtocolError> {
read_boundary(|| self.observe_inner(context, request))
}
fn observe_inner(
&self,
context: &ExecutionContext,
request: &ObserveRequest,
) -> Result<ObserveResponse, ProtocolError> {
request
.validate()
.map_err(|_| protocol(ProtocolErrorCode::InvalidRequest, "invalid observe request"))?;
if request.depth > self.projection.limits.max_observation_depth {
return Err(resource_protocol());
}
let entry = match self.resolve(context, &request.path) {
ProviderResult::Found(entry) => entry,
ProviderResult::NotFound => {
return Err(protocol(
ProtocolErrorCode::NotFound,
"target path is not published",
));
}
ProviderResult::Failure(error) => return Err(read_error(error)),
};
let mut remaining = u64::from(self.projection.limits.max_observation_nodes)
.min(context.resource_budget().unwrap_or(u64::MAX));
let response = self.observe_entry(context, entry, request.depth, &mut remaining)?;
request.validate_response(&response).map_err(|_| {
protocol(
ProtocolErrorCode::Internal,
"invalid projection observation",
)
})?;
Ok(response)
}
fn observe_entry(
&self,
context: &ExecutionContext,
entry: B::Entry,
depth: u32,
remaining: &mut u64,
) -> Result<ObjectObservation, ProtocolError> {
preflight(context).map_err(read_error)?;
if *remaining == 0 {
return Err(resource_protocol());
}
*remaining -= 1;
let object = self
.publication(entry.clone(), context)
.map_err(read_error)?
.protocol_object();
if depth == 0 {
return Ok(ObjectObservation {
object,
children: None,
});
}
let mut children = Vec::new();
if entry.kind() == EntryKind::Directory {
let entries = self
.projection
.backend
.children(
context,
&entry,
usize::try_from(*remaining).unwrap_or(usize::MAX),
)
.map_err(read_error)?;
if entries.len() as u64 > *remaining {
return Err(resource_protocol());
}
for child in entries {
if self
.projection
.policy
.object_visible(self.principal, &child)
{
children.push(self.observe_entry(context, child, depth - 1, remaining)?);
} else {
if *remaining == 0 {
return Err(resource_protocol());
}
*remaining -= 1;
}
}
}
Ok(ObjectObservation {
object,
children: Some(children),
})
}
}
impl<B, C, P> ObjectProvider for ProjectionView<'_, B, C, P>
where
B: FilesystemBackend,
C: Composition<B::Entry>,
P: ProjectionPolicy<B::Entry, C::Object>,
{
type Object = C::Object;
fn with_object<R>(
&self,
context: &ExecutionContext,
path: &str,
operation: impl FnOnce(&PublishedObject<Self::Object>) -> R,
) -> ProviderResult<R> {
match self.resolve(context, path) {
ProviderResult::Found(entry) => match self.publication(entry, context) {
Ok(publication) => ProviderResult::Found(operation(&publication)),
Err(error) => ProviderResult::Failure(error),
},
ProviderResult::NotFound => ProviderResult::NotFound,
ProviderResult::Failure(error) => ProviderResult::Failure(error),
}
}
fn execute_operation(
&self,
context: &ExecutionContext,
path: &str,
operation: impl FnOnce(&PublishedObject<Self::Object>) -> OperationAttempt,
) -> ProviderResult<OperationAttempt> {
let entry = match self.resolve(context, path) {
ProviderResult::Found(entry) => entry,
ProviderResult::NotFound => return ProviderResult::NotFound,
ProviderResult::Failure(error) => return ProviderResult::Failure(error),
};
self.projection.backend.execute(context, entry, |entry| {
// Recheck visibility using the atomic-boundary snapshot.
// Failure here is still pre-dispatch, with no operation effects.
if !self
.projection
.policy
.object_visible(self.principal, &entry)
{
return OperationAttempt::reject(wip_host::CallErrorKind::NotFound);
}
if let Err(error) = preflight(context) {
return OperationAttempt::reject(match error.kind() {
wip_host::HostErrorKind::Internal => wip_host::CallErrorKind::Internal,
wip_host::HostErrorKind::ResourceLimitExceeded => {
wip_host::CallErrorKind::ResourceLimitExceeded
}
});
}
match self.publication(entry, context) {
Ok(publication) => operation(&publication),
Err(error) => OperationAttempt::reject(match error.kind() {
wip_host::HostErrorKind::Internal => wip_host::CallErrorKind::Internal,
wip_host::HostErrorKind::ResourceLimitExceeded => {
wip_host::CallErrorKind::ResourceLimitExceeded
}
}),
}
})
}
fn authorize(
&self,
_: &str,
object: &Self::Object,
interface: &InterfaceRef,
operation: &str,
) -> bool {
self.projection
.policy
.authorize(self.principal, object, interface, operation)
}
}
impl<B, C, P> ObjectProvider for Projection<B, C, P>
where
B: FilesystemBackend,
C: Composition<B::Entry>,
P: ProjectionPolicy<B::Entry, C::Object, Principal = ()>,
{
type Object = C::Object;
fn with_object<R>(
&self,
context: &ExecutionContext,
path: &str,
operation: impl FnOnce(&PublishedObject<Self::Object>) -> R,
) -> ProviderResult<R> {
self.view(&()).with_object(context, path, operation)
}
fn execute_operation(
&self,
context: &ExecutionContext,
path: &str,
operation: impl FnOnce(&PublishedObject<Self::Object>) -> OperationAttempt,
) -> ProviderResult<OperationAttempt> {
self.view(&()).execute_operation(context, path, operation)
}
fn authorize(
&self,
path: &str,
object: &Self::Object,
interface: &InterfaceRef,
operation: &str,
) -> bool {
self.view(&()).authorize(path, object, interface, operation)
}
}
impl<B, C, P> Projection<B, C, P>
where
B: FilesystemBackend,
C: Composition<B::Entry>,
P: ProjectionPolicy<B::Entry, C::Object, Principal = ()>,
{
/// Observe the default unit-principal view.
pub fn observe(
&self,
context: &ExecutionContext,
request: &ObserveRequest,
) -> Result<ObserveResponse, ProtocolError> {
self.view(&()).observe(context, request)
}
/// Fetch in the default unit-principal view.
pub fn fetch_interface(
&self,
request: &FetchInterfaceRequest,
) -> Result<FetchInterfaceResponse, ProtocolError> {
self.view(&()).fetch_interface(request)
}
}
fn read_boundary<T>(
operation: impl FnOnce() -> Result<T, ProtocolError>,
) -> Result<T, ProtocolError> {
std::panic::catch_unwind(std::panic::AssertUnwindSafe(operation))
.unwrap_or_else(|_| Err(protocol(ProtocolErrorCode::Internal, "projection failed")))
}
fn internal() -> HostError {
HostError::internal(
"projection publication failed",
EffectGuarantee::NotCommitted,
)
}
fn protocol(code: ProtocolErrorCode, message: &str) -> ProtocolError {
ProtocolError {
code,
message: message.into(),
}
}
fn resource_protocol() -> ProtocolError {
protocol(
ProtocolErrorCode::ResourceLimitExceeded,
"projection resource limit exceeded",
)
}
fn read_error(error: HostError) -> ProtocolError {
match error.kind() {
wip_host::HostErrorKind::ResourceLimitExceeded => resource_protocol(),
wip_host::HostErrorKind::Internal => {
protocol(ProtocolErrorCode::Internal, "projection failed")
}
}
}
fn preflight(context: &ExecutionContext) -> Result<(), HostError> {
if context.cancellation().is_cancelled()
|| context
.deadline()
.is_some_and(|deadline| std::time::Instant::now() >= deadline)
|| context.resource_budget() == Some(0)
{
Err(HostError::resource_limit(
"projection work limit exceeded",
EffectGuarantee::NotCommitted,
))
} else {
Ok(())
}
}
+435
View File
@@ -0,0 +1,435 @@
//! Framework-neutral standard WIP over HTTP mapping for a projection view.
use std::time::Instant;
use http::header::ALLOW;
use http::{Request, Response, StatusCode};
use wip_host::{ExecutionContext, ObjectProvider};
use wip_http::{
CodecError, EncodeHttpError, Endpoint, RequestMetadataError, Route,
decode_call_operation_metadata, decode_fetch_interface_request, decode_observe_request,
encode_call_operation_response, encode_fetch_interface_response, encode_observe_response,
encode_protocol_error_response, validate_http_request,
};
use wip_protocol::{ProtocolError, ProtocolErrorCode, ProtocolInteraction};
use crate::engine::ProjectionView;
use crate::{Composition, FilesystemBackend, ProjectionPolicy, ResourceLimits};
/// Standard HTTP routes and codecs over a caller-scoped projection view.
///
/// The adapter borrows the view and endpoint without owning a listener, selecting
/// a principal, or imposing a new execution context. Integrations must enforce
/// the request body limit while collecting bytes, before calling this adapter.
pub struct HttpAdapter<'a, 'view, B, C, P>
where
B: FilesystemBackend,
C: Composition<B::Entry>,
P: ProjectionPolicy<B::Entry, C::Object>,
{
view: &'a ProjectionView<'view, B, C, P>,
endpoint: &'a Endpoint,
limits: ResourceLimits,
}
impl<'a, 'view, B, C, P> HttpAdapter<'a, 'view, B, C, P>
where
B: FilesystemBackend,
C: Composition<B::Entry>,
P: ProjectionPolicy<B::Entry, C::Object>,
{
/// Creates an adapter for an already-selected principal's projection view.
#[must_use]
pub fn new(
view: &'a ProjectionView<'view, B, C, P>,
endpoint: &'a Endpoint,
limits: ResourceLimits,
) -> Self {
Self {
view,
endpoint,
limits,
}
}
/// Handles one buffered request using the supplied execution controls.
///
/// Observation and operation dispatch receive the original context, including
/// cancellation and resource budget. An elapsed deadline after dispatch keeps
/// the listener's existing empty HTTP 504 transport-failure behavior.
#[must_use]
pub fn handle_http_with_context(
&self,
request: Request<Vec<u8>>,
context: &ExecutionContext,
) -> Response<Vec<u8>> {
let Some(route) = self.route(request.uri()) else {
return empty_response(StatusCode::NOT_FOUND);
};
if let Err(error) = validate_http_request(self.endpoint, route, &request) {
return self.metadata_error(error);
}
let response = match route {
Route::Observe => self.observe(request.body(), context),
Route::FetchInterface => self.fetch_interface(request.body()),
Route::CallOperation => self.call_operation(request.body(), context),
};
if context
.deadline()
.is_some_and(|deadline| Instant::now() >= deadline)
{
empty_response(StatusCode::GATEWAY_TIMEOUT)
} else {
response
}
}
fn route(&self, uri: &http::Uri) -> Option<Route> {
if uri.query().is_some() {
return None;
}
[Route::Observe, Route::FetchInterface, Route::CallOperation]
.into_iter()
.find(|route| self.endpoint.route(*route).path() == uri.path())
}
fn observe(&self, body: &[u8], context: &ExecutionContext) -> Response<Vec<u8>> {
let request = match decode_observe_request(body, self.limits.wire) {
Ok(request) => request,
Err(error) => return self.codec_error(ProtocolInteraction::Observe, error),
};
match self.view.observe(context, &request) {
Ok(tree) => {
encode_observe_response(&request, &tree, self.limits.wire).unwrap_or_else(|error| {
self.read_encode_error(ProtocolInteraction::Observe, error)
})
}
Err(error) => self.protocol_error(ProtocolInteraction::Observe, &error),
}
}
fn fetch_interface(&self, body: &[u8]) -> Response<Vec<u8>> {
let request = match decode_fetch_interface_request(body, self.limits.wire) {
Ok(request) => request,
Err(error) => return self.codec_error(ProtocolInteraction::FetchInterface, error),
};
match self.view.fetch_interface(&request) {
Ok(interface) => {
encode_fetch_interface_response(&request, &interface, self.limits.wire)
.unwrap_or_else(|error| {
self.read_encode_error(ProtocolInteraction::FetchInterface, error)
})
}
Err(error) => self.protocol_error(ProtocolInteraction::FetchInterface, &error),
}
}
fn call_operation(&self, body: &[u8], context: &ExecutionContext) -> Response<Vec<u8>> {
let metadata = match decode_call_operation_metadata(body, self.limits.wire) {
Ok(metadata) => metadata,
Err(error) => return self.codec_error(ProtocolInteraction::CallOperation, error),
};
let decoded = std::sync::Mutex::new(None);
let execution = self.view.call_operation_with_context_and_decoder(
context,
metadata.target.clone(),
metadata.interface.clone(),
metadata.operation.clone(),
|descriptor| {
let request = metadata.decode_request(body, descriptor, self.limits.wire)?;
let arguments = request.arguments.clone();
*decoded.lock().unwrap_or_else(|error| error.into_inner()) =
Some((request, descriptor.clone()));
Ok::<_, CodecError>(arguments)
},
);
match execution.map_err(|error| error.protocol_error()) {
Ok(result) => {
let Some((request, descriptor)) = decoded
.into_inner()
.unwrap_or_else(|error| error.into_inner())
else {
return self.protocol_error(
ProtocolInteraction::CallOperation,
&operation_outcome_unknown(),
);
};
encode_call_operation_response(&request, &descriptor, &result, self.limits.wire)
.unwrap_or_else(|error| self.operation_encode_error(error))
}
Err(error) => self.protocol_error(ProtocolInteraction::CallOperation, &error),
}
}
fn operation_encode_error(&self, error: EncodeHttpError) -> Response<Vec<u8>> {
if matches!(&error, EncodeHttpError::Codec(codec) if is_transport_limit(codec)) {
return empty_response(StatusCode::INTERNAL_SERVER_ERROR);
}
// Any successfully executed operation may have committed effects. Its
// name cannot establish a non-commit guarantee after response failure.
self.protocol_error(
ProtocolInteraction::CallOperation,
&operation_outcome_unknown(),
)
}
fn metadata_error(&self, error: RequestMetadataError) -> Response<Vec<u8>> {
match error {
RequestMetadataError::NotFound => empty_response(StatusCode::NOT_FOUND),
error @ RequestMetadataError::MethodNotAllowed => Response::builder()
.status(error.status())
.header(
ALLOW,
error
.allow()
.expect("method-not-allowed metadata has an Allow value"),
)
.body(Vec::new())
.expect("static method response is valid"),
RequestMetadataError::UnsupportedMediaType => {
empty_response(StatusCode::UNSUPPORTED_MEDIA_TYPE)
}
RequestMetadataError::NotAcceptable => empty_response(StatusCode::NOT_ACCEPTABLE),
}
}
fn codec_error(
&self,
interaction: ProtocolInteraction,
error: CodecError,
) -> Response<Vec<u8>> {
if is_transport_limit(&error) {
empty_response(StatusCode::PAYLOAD_TOO_LARGE)
} else {
self.protocol_error(
interaction,
&ProtocolError {
code: ProtocolErrorCode::InvalidRequest,
message: "malformed WIP request".into(),
},
)
}
}
fn read_encode_error(
&self,
interaction: ProtocolInteraction,
error: EncodeHttpError,
) -> Response<Vec<u8>> {
match error {
EncodeHttpError::Codec(codec) if is_transport_limit(&codec) => {
empty_response(StatusCode::INTERNAL_SERVER_ERROR)
}
_ => self.protocol_error(
interaction,
&ProtocolError {
code: ProtocolErrorCode::Internal,
message: "HTTP adapter failed".into(),
},
),
}
}
fn protocol_error(
&self,
interaction: ProtocolInteraction,
error: &ProtocolError,
) -> Response<Vec<u8>> {
// Engine and policy diagnostics may contain paths, argument values, or
// backend details. Emit only fixed, bounded diagnostics on the wire.
let sanitized = ProtocolError {
code: error.code,
message: sanitized_message(error.code).into(),
};
encode_protocol_error_response(interaction, &sanitized, self.limits.wire)
.unwrap_or_else(|_| empty_response(StatusCode::INTERNAL_SERVER_ERROR))
}
}
fn operation_outcome_unknown() -> ProtocolError {
ProtocolError {
code: ProtocolErrorCode::OperationOutcomeUnknown,
message: "operation completed but its response could not be encoded".into(),
}
}
fn sanitized_message(code: ProtocolErrorCode) -> &'static str {
match code {
ProtocolErrorCode::InvalidRequest => "malformed WIP request",
ProtocolErrorCode::NotFound => "target path is not published",
ProtocolErrorCode::InterfaceNotFound => "interface is not published",
ProtocolErrorCode::InterfaceMismatch => "interface is not published on the target",
ProtocolErrorCode::OperationNotFound => "operation is not published",
ProtocolErrorCode::InvalidArguments => "arguments do not match the operation",
ProtocolErrorCode::ValidatorRequired => "object validator is required",
ProtocolErrorCode::ValidatorMismatch => "object validator does not match",
ProtocolErrorCode::InterfaceValidatorRequired => "interface validator is required",
ProtocolErrorCode::InterfaceValidatorMismatch => "interface validator does not match",
ProtocolErrorCode::PermissionDenied => "operation is not permitted",
ProtocolErrorCode::ResourceLimitExceeded => "projection resource limit exceeded",
ProtocolErrorCode::Internal => "HTTP adapter failed",
ProtocolErrorCode::OperationOutcomeUnknown => "operation outcome is unknown",
}
}
fn is_transport_limit(error: &CodecError) -> bool {
matches!(
error,
CodecError::BodyTooLarge { .. } | CodecError::NestingTooDeep { .. }
)
}
fn empty_response(status: StatusCode) -> Response<Vec<u8>> {
Response::builder()
.status(status)
.body(Vec::new())
.expect("static status builds an HTTP response")
}
#[cfg(test)]
mod tests {
use super::*;
use tempfile::tempdir;
use wip_http::{
DecodedResponse, Limits, decode_fetch_interface_response, decode_observe_response,
encode_fetch_interface_request, encode_observe_request,
};
use wip_protocol::{FetchInterfaceRequest, ObserveRequest};
#[test]
fn adapter_serves_observation_and_interface_fetch_without_server() {
let root = tempdir().unwrap();
std::fs::write(root.path().join("file"), b"contents").unwrap();
let limits = ResourceLimits::default();
let projection =
crate::default_projection(root.path(), crate::AccessMode::ReadOnly, limits).unwrap();
let view = projection.view(&());
let endpoint = Endpoint::parse("http://localhost/custom").unwrap();
let adapter = HttpAdapter::new(&view, &endpoint, limits);
let context = ExecutionContext::new();
let request = ObserveRequest {
path: "/file".into(),
depth: 0,
};
let response = adapter.handle_http_with_context(
encode_observe_request(&endpoint, &request, limits.wire).unwrap(),
&context,
);
let DecodedResponse::Success(observation) =
decode_observe_response(&request, &response, limits.wire).unwrap()
else {
panic!("expected observation success")
};
let request = FetchInterfaceRequest {
interface: observation.object.interfaces[0].clone(),
};
let response = adapter.handle_http_with_context(
encode_fetch_interface_request(&endpoint, &request, limits.wire).unwrap(),
&context,
);
assert!(matches!(
decode_fetch_interface_response(&request, &response, limits.wire).unwrap(),
DecodedResponse::Success(_)
));
}
#[test]
fn adapter_preserves_transport_boundaries_and_execution_context() {
let root = tempdir().unwrap();
let limits = ResourceLimits::default();
let projection =
crate::default_projection(root.path(), crate::AccessMode::ReadOnly, limits).unwrap();
let view = projection.view(&());
let endpoint = Endpoint::parse("http://localhost/wip").unwrap();
let adapter = HttpAdapter::new(&view, &endpoint, limits);
let context = ExecutionContext::new();
for uri in [
"/wip/v1/observe?query=1",
"/wip/v1/unknown",
"/wip/v1/observe/extra",
] {
let response = adapter.handle_http_with_context(
Request::builder().uri(uri).body(Vec::new()).unwrap(),
&context,
);
assert_eq!(response.status(), StatusCode::NOT_FOUND);
assert!(response.body().is_empty());
}
let response = adapter.handle_http_with_context(
Request::builder()
.uri("/wip/v1/observe")
.body(Vec::new())
.unwrap(),
&context,
);
assert_eq!(response.status(), StatusCode::METHOD_NOT_ALLOWED);
assert_eq!(response.headers()[ALLOW], "POST");
assert!(response.body().is_empty());
let request = ObserveRequest {
path: "/".into(),
depth: 0,
};
let response = adapter.handle_http_with_context(
encode_observe_request(&endpoint, &request, limits.wire).unwrap(),
&ExecutionContext::new().with_resource_budget(0),
);
let text = std::str::from_utf8(response.body()).unwrap();
assert!(text.contains("resource_limit_exceeded"));
let response = adapter.handle_http_with_context(
encode_observe_request(&endpoint, &request, limits.wire).unwrap(),
&ExecutionContext::new().with_deadline(Instant::now()),
);
assert_eq!(response.status(), StatusCode::GATEWAY_TIMEOUT);
assert!(response.body().is_empty());
}
#[test]
fn post_success_encoding_is_unknown_except_empty_transport_limit_failure() {
let root = tempdir().unwrap();
let limits = ResourceLimits::default();
let projection =
crate::default_projection(root.path(), crate::AccessMode::ReadOnly, limits).unwrap();
let view = projection.view(&());
let endpoint = Endpoint::parse("http://localhost/wip").unwrap();
let adapter = HttpAdapter::new(&view, &endpoint, limits);
let error = decode_observe_request(b"{", limits.wire).unwrap_err();
let response = adapter.operation_encode_error(EncodeHttpError::Codec(error));
assert!(
std::str::from_utf8(response.body())
.unwrap()
.contains("operation_outcome_unknown")
);
let tiny_limits = Limits::new(1, 1, 1).unwrap();
let error = decode_observe_request(b"{}", tiny_limits).unwrap_err();
assert!(is_transport_limit(&error));
let response = adapter.operation_encode_error(EncodeHttpError::Codec(error));
assert_eq!(response.status(), StatusCode::INTERNAL_SERVER_ERROR);
assert!(response.body().is_empty());
assert!(!response.headers().contains_key(http::header::CONTENT_TYPE));
}
#[test]
fn engine_error_diagnostics_are_sanitized_and_bounded() {
let root = tempdir().unwrap();
let limits = ResourceLimits::default();
let projection =
crate::default_projection(root.path(), crate::AccessMode::ReadOnly, limits).unwrap();
let view = projection.view(&());
let endpoint = Endpoint::parse("http://localhost/wip").unwrap();
let adapter = HttpAdapter::new(&view, &endpoint, limits);
let response = adapter.protocol_error(
ProtocolInteraction::Observe,
&ProtocolError {
code: ProtocolErrorCode::Internal,
message: "/private/backend/secret".repeat(1000),
},
);
assert!(response.body().len() < 512);
assert!(
!std::str::from_utf8(response.body())
.unwrap()
.contains("secret")
);
assert_eq!(response.status(), StatusCode::INTERNAL_SERVER_ERROR);
}
}
+45 -1
View File
@@ -7,12 +7,46 @@
//! - [`wip_http`] owns routes, JSON, envelopes, and status mapping;
//! - this crate owns the filesystem capability boundary and the real HTTP listener.
//!
//! # Extension boundary
//!
//! [`Projection`] composes a [`FilesystemBackend`], typed [`Composition`] and
//! [`ProjectionPolicy`]. External local Objects can wrap a [`BackendEntry`] and
//! implement generated interfaces without orphan-rule workarounds. The backend
//! retains a root-confined target and atomic validator/dispatch boundary; the
//! engine owns recursive observation and standard host typed validation. No
//! listener is needed to use [`ProjectionView`]. [`HttpAdapter`] applies the
//! existing standard HTTP binding to a deployment-established principal view.
//!
//! Backends and Operations are trusted code, responsible for truthful effects,
//! public-only metadata and ongoing execution-context bounds. Policies must be
//! stable within a view; changing descriptor visibility requires new reference
//! lifetimes. See the crate README for implementer security and migration details.
//!
//! ```no_run
//! use wip_fs_server::{default_projection, AccessMode, ResourceLimits};
//! use wip_host::{ExecutionContext, ObjectProvider};
//! use wip_protocol::ObserveRequest;
//!
//! let engine = default_projection(std::path::Path::new("./public"),
//! AccessMode::ReadOnly, ResourceLimits::default())?;
//! let view = engine.view(&());
//! let context = ExecutionContext::new().with_resource_budget(128);
//! let tree = view.observe(&context, &ObserveRequest { path: "/".into(), depth: 1 })?;
//! assert_eq!(tree.object.name, "");
//! let object = view.observe_object_with_context(&context, "/")?;
//! assert!(object.interfaces.is_empty());
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! The built-in HTTP listener is intentionally loopback-only. TLS termination,
//! certificates, authentication, and externally visible schemes are independent
//! deployment concerns rather than WIP transport profiles.
#![deny(missing_docs)]
mod defaults;
mod engine;
mod http_adapter;
mod interfaces;
mod projection;
mod server;
@@ -21,7 +55,17 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::path::PathBuf;
use std::time::Duration;
pub use interfaces::{FileRead, FileWrite, SymlinkInspect};
pub use defaults::{DefaultComposition, DefaultInterfaces, DefaultObject, default_projection};
pub use engine::{
BackendEntry, Composition, DefaultPolicy, EntryKind, FilesystemBackend, Projection,
ProjectionPolicy, ProjectionView,
};
pub use http_adapter::HttpAdapter;
pub use interfaces::{
FileRead, FileReadDefinition, FileWrite, FileWriteDefinition, SymlinkInspect,
SymlinkInspectDefinition,
};
pub use projection::{LinuxBackend, LinuxEntry};
pub use server::{BoundServer, ServerBuildError, WipFsServer};
/// Filesystem capabilities published by regular files.
File diff suppressed because it is too large Load Diff
+12 -210
View File
@@ -5,26 +5,20 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::thread;
use std::time::{Duration, Instant};
use http::header::ALLOW;
use http::{Request, Response, StatusCode};
use wip_host::{ExecutionContext, ObjectProvider};
use wip_http::{
CodecError, EncodeHttpError, Endpoint, RequestMetadataError, Route,
decode_call_operation_metadata, decode_fetch_interface_request, decode_observe_request,
encode_call_operation_response, encode_fetch_interface_response, encode_observe_response,
encode_protocol_error_response, validate_http_request,
};
use wip_protocol::{ProtocolError, ProtocolErrorCode, ProtocolInteraction};
use wip_host::ExecutionContext;
use wip_http::Endpoint;
use crate::projection::Projection;
use crate::{ConfigError, ServerConfig};
use crate::engine::Projection;
use crate::http_adapter::HttpAdapter;
use crate::{ConfigError, DefaultComposition, DefaultPolicy, LinuxBackend, ServerConfig};
/// Filesystem projection and framework-neutral standard WIP request adapter.
/// Default Linux filesystem projection and bounded loopback HTTP listener.
pub struct WipFsServer {
config: ServerConfig,
endpoint: Endpoint,
effective_root: std::path::PathBuf,
projection: Arc<Projection>,
projection: Arc<Projection<LinuxBackend, DefaultComposition, DefaultPolicy>>,
}
impl WipFsServer {
@@ -32,8 +26,8 @@ impl WipFsServer {
pub fn new(config: ServerConfig) -> Result<Self, ServerBuildError> {
config.validate()?;
let endpoint = config.endpoint()?;
let projection = Projection::open(&config.root, config.access, config.limits)?;
let effective_root = projection.effective_root()?;
let projection = crate::default_projection(&config.root, config.access, config.limits)?;
let effective_root = projection.backend().effective_root()?;
Ok(Self {
config,
endpoint,
@@ -67,25 +61,12 @@ impl WipFsServer {
request: Request<Vec<u8>>,
deadline: Instant,
) -> Response<Vec<u8>> {
let Some(route) = self.route(request.uri()) else {
return empty_response(StatusCode::NOT_FOUND);
};
if let Err(error) = validate_http_request(&self.endpoint, route, &request) {
return self.metadata_error(error);
}
let context = ExecutionContext::new()
.with_deadline(deadline)
.with_resource_budget(u64::from(self.config.limits.max_observation_nodes));
let response = match route {
Route::Observe => self.observe(request.body(), &context),
Route::FetchInterface => self.fetch_interface(request.body()),
Route::CallOperation => self.call_operation(request.body(), &context),
};
if Instant::now() >= deadline {
empty_response(StatusCode::GATEWAY_TIMEOUT)
} else {
response
}
let view = self.projection.view(&());
HttpAdapter::new(&view, &self.endpoint, self.config.limits)
.handle_http_with_context(request, &context)
}
/// Binds the built-in bounded loopback HTTP listener.
@@ -108,171 +89,6 @@ impl WipFsServer {
listener: Arc::new(listener),
})
}
fn route(&self, uri: &http::Uri) -> Option<Route> {
if uri.query().is_some() {
return None;
}
[Route::Observe, Route::FetchInterface, Route::CallOperation]
.into_iter()
.find(|route| self.endpoint.route(*route).path() == uri.path())
}
fn observe(&self, body: &[u8], context: &ExecutionContext) -> Response<Vec<u8>> {
let request = match decode_observe_request(body, self.config.limits.wire) {
Ok(request) => request,
Err(error) => return self.codec_error(ProtocolInteraction::Observe, error),
};
match self.projection.observe(context, &request) {
Ok(tree) => encode_observe_response(&request, &tree, self.config.limits.wire)
.unwrap_or_else(|error| {
self.read_encode_error(ProtocolInteraction::Observe, error)
}),
Err(error) => self.protocol_error(ProtocolInteraction::Observe, &error),
}
}
fn fetch_interface(&self, body: &[u8]) -> Response<Vec<u8>> {
let request = match decode_fetch_interface_request(body, self.config.limits.wire) {
Ok(request) => request,
Err(error) => return self.codec_error(ProtocolInteraction::FetchInterface, error),
};
match self.projection.fetch_interface(&request) {
Ok(interface) => {
encode_fetch_interface_response(&request, &interface, self.config.limits.wire)
.unwrap_or_else(|error| {
self.read_encode_error(ProtocolInteraction::FetchInterface, error)
})
}
Err(error) => self.protocol_error(ProtocolInteraction::FetchInterface, &error),
}
}
fn call_operation(&self, body: &[u8], context: &ExecutionContext) -> Response<Vec<u8>> {
let metadata = match decode_call_operation_metadata(body, self.config.limits.wire) {
Ok(metadata) => metadata,
Err(error) => return self.codec_error(ProtocolInteraction::CallOperation, error),
};
let may_commit = metadata.operation == "replace";
let decoded = std::sync::Mutex::new(None);
let execution = self.projection.call_operation_with_context_and_decoder(
context,
metadata.target.clone(),
metadata.interface.clone(),
metadata.operation.clone(),
|descriptor| {
let request = metadata.decode_request(body, descriptor, self.config.limits.wire)?;
let arguments = request.arguments.clone();
*decoded.lock().unwrap_or_else(|error| error.into_inner()) =
Some((request, descriptor.clone()));
Ok::<_, CodecError>(arguments)
},
);
match execution.map_err(|error| error.protocol_error()) {
Ok(result) => {
let Some((request, descriptor)) = decoded
.into_inner()
.unwrap_or_else(|error| error.into_inner())
else {
let error = ProtocolError {
code: if may_commit {
ProtocolErrorCode::OperationOutcomeUnknown
} else {
ProtocolErrorCode::Internal
},
message: "operation completed without response metadata".into(),
};
return self.protocol_error(ProtocolInteraction::CallOperation, &error);
};
encode_call_operation_response(
&request,
&descriptor,
&result,
self.config.limits.wire,
)
.unwrap_or_else(|encode_error| {
if matches!(
&encode_error,
EncodeHttpError::Codec(codec) if is_transport_limit(codec)
) {
return empty_response(StatusCode::INTERNAL_SERVER_ERROR);
}
if !may_commit {
return self
.read_encode_error(ProtocolInteraction::CallOperation, encode_error);
}
// Replacement may already be committed, so a response
// encoding failure cannot carry a non-commit guarantee.
let error = ProtocolError {
code: ProtocolErrorCode::OperationOutcomeUnknown,
message: "operation completed but its response could not be encoded".into(),
};
self.protocol_error(ProtocolInteraction::CallOperation, &error)
})
}
Err(error) => self.protocol_error(ProtocolInteraction::CallOperation, &error),
}
}
fn metadata_error(&self, error: RequestMetadataError) -> Response<Vec<u8>> {
match error {
RequestMetadataError::NotFound => empty_response(StatusCode::NOT_FOUND),
error @ RequestMetadataError::MethodNotAllowed => Response::builder()
.status(error.status())
.header(
ALLOW,
error
.allow()
.expect("method-not-allowed metadata has an Allow value"),
)
.body(Vec::new())
.expect("static method response is valid"),
RequestMetadataError::UnsupportedMediaType => {
empty_response(StatusCode::UNSUPPORTED_MEDIA_TYPE)
}
RequestMetadataError::NotAcceptable => empty_response(StatusCode::NOT_ACCEPTABLE),
}
}
fn codec_error(
&self,
interaction: ProtocolInteraction,
error: CodecError,
) -> Response<Vec<u8>> {
if is_transport_limit(&error) {
empty_response(StatusCode::PAYLOAD_TOO_LARGE)
} else {
self.protocol_error(
interaction,
&ProtocolError {
code: ProtocolErrorCode::InvalidRequest,
message: "malformed WIP request".into(),
},
)
}
}
fn read_encode_error(
&self,
interaction: ProtocolInteraction,
error: EncodeHttpError,
) -> Response<Vec<u8>> {
match error {
EncodeHttpError::Codec(codec) if is_transport_limit(&codec) => {
empty_response(StatusCode::INTERNAL_SERVER_ERROR)
}
_ => self.protocol_error(interaction, &internal_error()),
}
}
fn protocol_error(
&self,
interaction: ProtocolInteraction,
error: &ProtocolError,
) -> Response<Vec<u8>> {
encode_protocol_error_response(interaction, error, self.config.limits.wire)
.unwrap_or_else(|_| empty_response(StatusCode::INTERNAL_SERVER_ERROR))
}
}
/// Bound real HTTP listener for a [`WipFsServer`].
@@ -560,20 +376,6 @@ fn write_all_with_deadline(
stream.flush()
}
fn is_transport_limit(error: &CodecError) -> bool {
matches!(
error,
CodecError::BodyTooLarge { .. } | CodecError::NestingTooDeep { .. }
)
}
fn internal_error() -> ProtocolError {
ProtocolError {
code: ProtocolErrorCode::Internal,
message: "filesystem server failed".into(),
}
}
fn empty_response(status: StatusCode) -> Response<Vec<u8>> {
Response::builder()
.status(status)