55
66pub mod headers;
77mod remote;
8+ mod response;
89mod websocket;
910
11+ pub use response:: {
12+ HttpResponseDiagnostics , HttpResponseFinish , HttpResponseInvocation ,
13+ HttpResponseInvocationOutcome , HttpResponseMiddlewareFailure , HttpResponsePreflightInput ,
14+ HttpResponsePreflightOutcome , HttpResponseSession , MAX_HTTP_RESPONSE_RETAINED_BODY_BYTES ,
15+ MAX_HTTP_RESPONSE_STREAM_UNIT_BYTES , is_stale_http_response_integrity_header,
16+ } ;
17+
1018pub use websocket:: {
1119 WebSocketCoverage , WebSocketCoverageState , WebSocketInvocation , WebSocketInvocationOutcome ,
1220 WebSocketMessageAdmission , WebSocketMessageOutcome , WebSocketMessageType ,
@@ -626,6 +634,16 @@ impl MiddlewareDispatch {
626634 Self :: Grpc ( service) => service. open_websocket_session ( receiver) . await ,
627635 }
628636 }
637+
638+ async fn open_http_response_pre_return (
639+ & self ,
640+ receiver : tokio:: sync:: mpsc:: Receiver < openshell_core:: proto:: HttpResponseEvent > ,
641+ ) -> std:: result:: Result < HttpResponseResultStream , tonic:: Status > {
642+ match self {
643+ Self :: InProcess ( service) => service. open_http_response_pre_return ( receiver) . await ,
644+ Self :: Grpc ( service) => service. open_http_response_pre_return ( receiver) . await ,
645+ }
646+ }
629647}
630648
631649struct MiddlewareServiceState {
@@ -836,6 +854,7 @@ fn validate_payload_limit(source: &str, binding: &MiddlewareBinding) -> Result<u
836854#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
837855enum SupportedBinding {
838856 HttpPreCredentials ,
857+ HttpResponsePreReturn ,
839858 WebSocketPreCredentials ,
840859}
841860
@@ -851,9 +870,7 @@ fn supported_binding(source: &str, binding: &MiddlewareBinding) -> Result<Suppor
851870 (
852871 Some ( SupervisorMiddlewareOperation :: HttpResponse ) ,
853872 Some ( SupervisorMiddlewarePhase :: PreReturn ) ,
854- ) => Err ( miette ! (
855- "{source} advertises HTTP_RESPONSE/PRE_RETURN, which is not yet supported"
856- ) ) ,
873+ ) => Ok ( SupportedBinding :: HttpResponsePreReturn ) ,
857874 (
858875 Some ( SupervisorMiddlewareOperation :: WebsocketMessage ) ,
859876 Some ( SupervisorMiddlewarePhase :: PreCredentials ) ,
@@ -3721,7 +3738,7 @@ mod tests {
37213738 }
37223739
37233740 #[ test]
3724- fn manifest_rejects_http_response_pre_return_binding_until_dispatch_is_available ( ) {
3741+ fn manifest_accepts_http_response_pre_return_binding_when_dispatch_is_available ( ) {
37253742 let registration = external_registration ( 4096 ) ;
37263743 let manifest = MiddlewareManifest {
37273744 name : "example/response" . into ( ) ,
@@ -3738,13 +3755,8 @@ mod tests {
37383755 expected_audience : String :: new ( ) ,
37393756 } ;
37403757
3741- let error = validate_external_manifest ( & registration, & manifest, 4096 , false )
3742- . expect_err ( "HTTP response pre-return binding must remain unavailable" ) ;
3743- assert ! (
3744- error
3745- . to_string( )
3746- . contains( "HTTP_RESPONSE/PRE_RETURN, which is not yet supported" )
3747- ) ;
3758+ validate_external_manifest ( & registration, & manifest, 4096 , false )
3759+ . expect ( "HTTP response pre-return binding is supported" ) ;
37483760 }
37493761
37503762 #[ test]
0 commit comments