feat: remove retrieval batch over HTTP
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
Worldspace `/` at request time. It does not register the filesystem contents or
|
||||
keep one object instance per entry. It uses `wip-host` for publication and typed
|
||||
operation dispatch and uses the standard `wip-http` routes, JSON codecs,
|
||||
envelopes, batching, and HTTP status mapping.
|
||||
envelopes, and HTTP status mapping.
|
||||
|
||||
## Security model
|
||||
|
||||
@@ -118,14 +118,11 @@ curl -sS -X POST http://127.0.0.1:8080/wip/v1/call_operation \
|
||||
}'
|
||||
```
|
||||
|
||||
`observe` and `fetch_interface` can also be combined through the standard
|
||||
`POST /wip/v1/batch` route. `call_operation` is never batchable.
|
||||
|
||||
## Resource and failure behavior
|
||||
|
||||
`ResourceLimits` bounds request/response bytes, HTTP request-head bytes, JSON
|
||||
nesting, batch items, file read/write bytes, tree depth/node count, pinned handles,
|
||||
and active connections/requests. One absolute request deadline covers header and
|
||||
nesting, file read/write bytes, tree depth/node count, pinned handles, and active
|
||||
connections/requests. One absolute request deadline covers header and
|
||||
body intake, dispatch, cooperative filesystem work, and response transmission;
|
||||
stalled clients are closed and cannot occupy a worker beyond that bound. Workers
|
||||
accept connections directly, so the listener never moves more than the configured
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
//!
|
||||
//! - [`wip_protocol`] owns logical requests and responses;
|
||||
//! - [`wip_host`] owns object publication, validators, and typed dispatch;
|
||||
//! - [`wip_http`] owns routes, JSON, envelopes, batching, and status mapping;
|
||||
//! - [`wip_http`] owns routes, JSON, envelopes, and status mapping;
|
||||
//! - this crate owns the filesystem capability boundary and the real HTTP listener.
|
||||
//!
|
||||
//! The built-in HTTP listener is intentionally loopback-only. TLS termination,
|
||||
@@ -36,7 +36,7 @@ pub enum AccessMode {
|
||||
/// Bounded resource policy applied by the HTTP adapter and filesystem provider.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct ResourceLimits {
|
||||
/// Standard JSON, body-size, nesting, and batch limits.
|
||||
/// Standard JSON, body-size, and nesting limits.
|
||||
pub wire: wip_http::Limits,
|
||||
/// Maximum bytes returned by one file read.
|
||||
pub max_file_read_bytes: usize,
|
||||
@@ -59,7 +59,7 @@ pub struct ResourceLimits {
|
||||
impl Default for ResourceLimits {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
wire: wip_http::Limits::new(256 * 1024, 2 * 1024 * 1024, 64, 64)
|
||||
wire: wip_http::Limits::new(256 * 1024, 2 * 1024 * 1024, 64)
|
||||
.expect("default wire limits are nonzero"),
|
||||
max_file_read_bytes: 1024 * 1024,
|
||||
max_file_write_bytes: 1024 * 1024,
|
||||
|
||||
@@ -9,11 +9,10 @@ use http::header::ALLOW;
|
||||
use http::{Request, Response, StatusCode};
|
||||
use wip_host::{ExecutionContext, ObjectProvider};
|
||||
use wip_http::{
|
||||
BatchRequestKind, BatchResponse, BatchResponseItem, BatchSuccess, CodecError, EncodeHttpError,
|
||||
Endpoint, RequestMetadataError, Route, decode_batch_request, decode_call_operation_metadata,
|
||||
decode_fetch_interface_request, decode_observe_request, encode_batch_error_response,
|
||||
encode_batch_response, encode_call_operation_response, encode_fetch_interface_response,
|
||||
encode_observe_response, encode_protocol_error_response, validate_http_request,
|
||||
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};
|
||||
|
||||
@@ -81,7 +80,6 @@ impl WipFsServer {
|
||||
Route::Observe => self.observe(request.body(), &context),
|
||||
Route::FetchInterface => self.fetch_interface(request.body()),
|
||||
Route::CallOperation => self.call_operation(request.body(), &context),
|
||||
Route::Batch => self.batch(request.body(), &context),
|
||||
};
|
||||
if Instant::now() >= deadline {
|
||||
empty_response(StatusCode::GATEWAY_TIMEOUT)
|
||||
@@ -115,14 +113,9 @@ impl WipFsServer {
|
||||
if uri.query().is_some() {
|
||||
return None;
|
||||
}
|
||||
[
|
||||
Route::Observe,
|
||||
Route::FetchInterface,
|
||||
Route::CallOperation,
|
||||
Route::Batch,
|
||||
]
|
||||
.into_iter()
|
||||
.find(|route| self.endpoint.route(*route).path() == uri.path())
|
||||
[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>> {
|
||||
@@ -221,41 +214,6 @@ impl WipFsServer {
|
||||
}
|
||||
}
|
||||
|
||||
fn batch(&self, body: &[u8], context: &ExecutionContext) -> Response<Vec<u8>> {
|
||||
let request = match decode_batch_request(body, self.config.limits.wire) {
|
||||
Ok(request) => request,
|
||||
Err(error) => return self.batch_codec_error(error),
|
||||
};
|
||||
let responses = request
|
||||
.requests
|
||||
.iter()
|
||||
.map(|item| {
|
||||
let outcome = match &item.request {
|
||||
BatchRequestKind::Observe(request) => self
|
||||
.projection
|
||||
.observe(context, request)
|
||||
.map(BatchSuccess::Observe),
|
||||
BatchRequestKind::FetchInterface(request) => self
|
||||
.projection
|
||||
.fetch_interface(request)
|
||||
.map(BatchSuccess::FetchInterface),
|
||||
BatchRequestKind::Invalid { error, .. } => Err(error.clone()),
|
||||
};
|
||||
BatchResponseItem {
|
||||
id: item.id.clone(),
|
||||
outcome,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
let response = BatchResponse { responses };
|
||||
encode_batch_response(&request, &response, self.config.limits.wire).unwrap_or_else(
|
||||
|error| match error {
|
||||
EncodeHttpError::Codec(codec) => self.batch_encode_error(&codec),
|
||||
EncodeHttpError::Http(_) => self.batch_top_error(&internal_error()),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn metadata_error(&self, error: RequestMetadataError) -> Response<Vec<u8>> {
|
||||
match error {
|
||||
RequestMetadataError::NotFound => empty_response(StatusCode::NOT_FOUND),
|
||||
@@ -294,17 +252,6 @@ impl WipFsServer {
|
||||
}
|
||||
}
|
||||
|
||||
fn batch_codec_error(&self, error: CodecError) -> Response<Vec<u8>> {
|
||||
if is_transport_limit(&error) {
|
||||
empty_response(StatusCode::PAYLOAD_TOO_LARGE)
|
||||
} else {
|
||||
self.batch_top_error(&ProtocolError {
|
||||
code: ProtocolErrorCode::InvalidRequest,
|
||||
message: "malformed WIP batch request".into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn read_encode_error(
|
||||
&self,
|
||||
interaction: ProtocolInteraction,
|
||||
@@ -318,14 +265,6 @@ impl WipFsServer {
|
||||
}
|
||||
}
|
||||
|
||||
fn batch_encode_error(&self, error: &CodecError) -> Response<Vec<u8>> {
|
||||
if is_transport_limit(error) {
|
||||
empty_response(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
} else {
|
||||
self.batch_top_error(&internal_error())
|
||||
}
|
||||
}
|
||||
|
||||
fn protocol_error(
|
||||
&self,
|
||||
interaction: ProtocolInteraction,
|
||||
@@ -334,11 +273,6 @@ impl WipFsServer {
|
||||
encode_protocol_error_response(interaction, error, self.config.limits.wire)
|
||||
.unwrap_or_else(|_| empty_response(StatusCode::INTERNAL_SERVER_ERROR))
|
||||
}
|
||||
|
||||
fn batch_top_error(&self, error: &ProtocolError) -> Response<Vec<u8>> {
|
||||
encode_batch_error_response(error, self.config.limits.wire)
|
||||
.unwrap_or_else(|_| empty_response(StatusCode::INTERNAL_SERVER_ERROR))
|
||||
}
|
||||
}
|
||||
|
||||
/// Bound real HTTP listener for a [`WipFsServer`].
|
||||
@@ -629,9 +563,7 @@ fn write_all_with_deadline(
|
||||
fn is_transport_limit(error: &CodecError) -> bool {
|
||||
matches!(
|
||||
error,
|
||||
CodecError::BodyTooLarge { .. }
|
||||
| CodecError::NestingTooDeep { .. }
|
||||
| CodecError::TooManyBatchItems { .. }
|
||||
CodecError::BodyTooLarge { .. } | CodecError::NestingTooDeep { .. }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,9 @@ use std::time::{Duration, Instant};
|
||||
use tempfile::tempdir;
|
||||
use wip_fs_server::{AccessMode, ServerConfig, WipFsServer};
|
||||
use wip_http::{
|
||||
BatchRequest, BatchRequestItem, BatchRequestKind, BatchResponse, BatchSuccess,
|
||||
ClientResponseError, DecodedResponse, Endpoint, JSON_CONTENT_TYPE, Limits, Route,
|
||||
TransportFailureKind, decode_batch_request, decode_batch_response,
|
||||
decode_call_operation_response, decode_fetch_interface_response, decode_observe_response,
|
||||
encode_batch_request, encode_call_operation_request, encode_fetch_interface_request,
|
||||
TransportFailureKind, decode_call_operation_response, decode_fetch_interface_response,
|
||||
decode_observe_response, encode_call_operation_request, encode_fetch_interface_request,
|
||||
encode_observe_request,
|
||||
};
|
||||
use wip_protocol::{
|
||||
@@ -22,7 +20,7 @@ use wip_protocol::{
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn real_listener_serves_three_core_interactions_batch_and_write() {
|
||||
fn real_listener_serves_three_core_interactions_and_write() {
|
||||
let temporary = tempdir().expect("temporary root");
|
||||
std::fs::write(temporary.path().join("hello.txt"), b"hello world").expect("write file");
|
||||
std::fs::create_dir(temporary.path().join("nested")).expect("create directory");
|
||||
@@ -125,36 +123,6 @@ fn real_listener_serves_three_core_interactions_batch_and_write() {
|
||||
);
|
||||
assert_eq!(read.result, Value::Bytes(b"world".to_vec()));
|
||||
|
||||
let batch_request = BatchRequest {
|
||||
requests: vec![
|
||||
BatchRequestItem {
|
||||
id: "root".into(),
|
||||
request: BatchRequestKind::Observe(ObserveRequest {
|
||||
path: "/".into(),
|
||||
depth: 0,
|
||||
}),
|
||||
},
|
||||
BatchRequestItem {
|
||||
id: "tree".into(),
|
||||
request: BatchRequestKind::Observe(ObserveRequest {
|
||||
path: "/nested".into(),
|
||||
depth: 1,
|
||||
}),
|
||||
},
|
||||
BatchRequestItem {
|
||||
id: "interface".into(),
|
||||
request: BatchRequestKind::FetchInterface(read_interface_request.clone()),
|
||||
},
|
||||
],
|
||||
};
|
||||
let response = exchange(
|
||||
address,
|
||||
encode_batch_request(&endpoint, &batch_request, limits).expect("encode batch"),
|
||||
);
|
||||
let batch =
|
||||
success(decode_batch_response(&batch_request, &response, limits).expect("decode batch"));
|
||||
assert_batch_successes(&batch);
|
||||
|
||||
let write_interface_request = FetchInterfaceRequest {
|
||||
interface: file.interfaces[1].clone(),
|
||||
};
|
||||
@@ -215,7 +183,7 @@ fn real_listener_serves_three_core_interactions_batch_and_write() {
|
||||
fn real_listener_keeps_route_method_and_malformed_body_boundaries_distinct() {
|
||||
let temporary = tempdir().expect("temporary root");
|
||||
let mut config = ServerConfig::for_root(temporary.path());
|
||||
config.limits.wire = Limits::new(64, 4_096, 64, 4).expect("wire limits");
|
||||
config.limits.wire = Limits::new(64, 4_096, 64).expect("wire limits");
|
||||
let bound = Arc::new(
|
||||
WipFsServer::new(config)
|
||||
.expect("build server")
|
||||
@@ -232,6 +200,7 @@ fn real_listener_keeps_route_method_and_malformed_body_boundaries_distinct() {
|
||||
|
||||
for uri in [
|
||||
"/wip/v1/unknown",
|
||||
"/wip/v1/batch",
|
||||
"/wip/v1/observe?unexpected=true",
|
||||
"/wip/v1/observe/extra",
|
||||
] {
|
||||
@@ -239,6 +208,7 @@ fn real_listener_keeps_route_method_and_malformed_body_boundaries_distinct() {
|
||||
assert_eq!(response.status(), http::StatusCode::NOT_FOUND);
|
||||
assert!(response.body().is_empty());
|
||||
assert!(!response.headers().contains_key(http::header::CONTENT_TYPE));
|
||||
assert!(!response.headers().contains_key(http::header::ALLOW));
|
||||
}
|
||||
|
||||
let wrong_method = exchange(
|
||||
@@ -326,10 +296,10 @@ fn real_listener_keeps_route_method_and_malformed_body_boundaries_distinct() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raw_decoder_and_batch_packaging_limits_are_transport_failures() {
|
||||
fn raw_decoder_limits_are_transport_failures() {
|
||||
let temporary = tempdir().expect("temporary root");
|
||||
let mut config = ServerConfig::for_root(temporary.path());
|
||||
config.limits.wire = Limits::new(4_096, 4_096, 8, 1).expect("wire limits");
|
||||
config.limits.wire = Limits::new(4_096, 4_096, 8).expect("wire limits");
|
||||
let server = WipFsServer::new(config).expect("build server");
|
||||
|
||||
let nested = br#"{"path":[[[[[[[[["/"]]]]]]]]],"depth":0}"#;
|
||||
@@ -337,12 +307,6 @@ fn raw_decoder_and_batch_packaging_limits_are_transport_failures() {
|
||||
assert_eq!(response.status(), http::StatusCode::PAYLOAD_TOO_LARGE);
|
||||
assert!(response.body().is_empty());
|
||||
assert!(!response.headers().contains_key(http::header::CONTENT_TYPE));
|
||||
|
||||
let batch = br#"{"requests":[{"id":"one","method":"observe","arguments":{"path":"/","depth":0}},{"id":"two","method":"observe","arguments":{"path":"/","depth":0}}]}"#;
|
||||
let response = server.handle_http(json_request(http::Method::POST, "/wip/v1/batch", batch));
|
||||
assert_eq!(response.status(), http::StatusCode::PAYLOAD_TOO_LARGE);
|
||||
assert!(response.body().is_empty());
|
||||
assert!(!response.headers().contains_key(http::header::CONTENT_TYPE));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -442,37 +406,6 @@ fn stalled_request_body_times_out_and_releases_the_only_worker() {
|
||||
.expect("listener exits cleanly");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn batch_keeps_known_malformed_arguments_item_local() {
|
||||
let temporary = tempdir().expect("temporary root");
|
||||
let config = ServerConfig::for_root(temporary.path());
|
||||
let limits = config.limits.wire;
|
||||
let server = WipFsServer::new(config).expect("build server");
|
||||
let endpoint = Endpoint::parse("http://localhost/wip").expect("endpoint");
|
||||
let body = br#"{"requests":[{"id":"ok","method":"observe","arguments":{"path":"/","depth":0}},{"id":"bad","method":"observe","arguments":{"path":"/","depth":"bad"}}]}"#;
|
||||
let logical = decode_batch_request(body, limits).expect("decode item-local invalid request");
|
||||
assert!(matches!(
|
||||
logical.requests[1].request,
|
||||
BatchRequestKind::Invalid { .. }
|
||||
));
|
||||
let request = http::Request::builder()
|
||||
.method(http::Method::POST)
|
||||
.uri(endpoint.route(Route::Batch).as_str())
|
||||
.header(http::header::CONTENT_TYPE, JSON_CONTENT_TYPE)
|
||||
.header(http::header::ACCEPT, "application/json")
|
||||
.body(body.to_vec())
|
||||
.expect("build request");
|
||||
let response = server.handle_http(request);
|
||||
let batch = success(
|
||||
decode_batch_response(&logical, &response, limits).expect("decode mixed batch response"),
|
||||
);
|
||||
assert!(matches!(
|
||||
batch.responses[0].outcome,
|
||||
Ok(BatchSuccess::Observe(_))
|
||||
));
|
||||
assert!(batch.responses[1].outcome.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_argument_decoding_does_not_mask_missing_target() {
|
||||
let temporary = tempdir().expect("temporary root");
|
||||
@@ -524,7 +457,7 @@ fn read_response_size_failure_is_transport_local() {
|
||||
let temporary = tempdir().expect("temporary root");
|
||||
std::fs::write(temporary.path().join("large"), vec![b'x'; 2_000]).expect("write file");
|
||||
let mut config = ServerConfig::for_root(temporary.path());
|
||||
config.limits.wire = Limits::new(4_096, 1_024, 64, 64).expect("wire limits");
|
||||
config.limits.wire = Limits::new(4_096, 1_024, 64).expect("wire limits");
|
||||
let limits = config.limits.wire;
|
||||
let server = WipFsServer::new(config).expect("build server");
|
||||
let endpoint = Endpoint::parse("http://localhost/wip").expect("endpoint");
|
||||
@@ -579,22 +512,6 @@ fn read_response_size_failure_is_transport_local() {
|
||||
));
|
||||
}
|
||||
|
||||
fn assert_batch_successes(batch: &BatchResponse) {
|
||||
assert_eq!(batch.responses.len(), 3);
|
||||
assert!(matches!(
|
||||
batch.responses[0].outcome,
|
||||
Ok(BatchSuccess::Observe(_))
|
||||
));
|
||||
assert!(matches!(
|
||||
batch.responses[1].outcome,
|
||||
Ok(BatchSuccess::Observe(_))
|
||||
));
|
||||
assert!(matches!(
|
||||
batch.responses[2].outcome,
|
||||
Ok(BatchSuccess::FetchInterface(_))
|
||||
));
|
||||
}
|
||||
|
||||
fn success<T>(response: DecodedResponse<T>) -> T {
|
||||
match response {
|
||||
DecodedResponse::Success(value) => value,
|
||||
|
||||
Reference in New Issue
Block a user