@@ -9,7 +9,9 @@ use http::{request::HttpRequest, response::HttpResponse, server::Server};
99use std:: collections:: HashMap ;
1010use std:: sync:: Arc ;
1111use tonic:: async_trait;
12- use tucana:: shared:: ValidationFlow ;
12+ use tucana:: shared:: value:: Kind ;
13+ use tucana:: shared:: value:: Kind :: StructValue ;
14+ use tucana:: shared:: { Struct , ValidationFlow , Value } ;
1315
1416#[ tokio:: main]
1517async fn main ( ) {
@@ -96,10 +98,54 @@ async fn execute_flow(
9698) -> Option < HttpResponse > {
9799 match store. validate_and_execute_flow ( flow, request. body ) . await {
98100 Some ( result) => {
99- let json = serde_json:: to_vec_pretty ( & result) . unwrap_or_else ( |err| {
101+ let Value {
102+ kind : Some ( StructValue ( Struct { fields } ) ) ,
103+ } = result
104+ else {
105+ return None ;
106+ } ;
107+
108+ let Some ( headers) = fields. get ( "headers" ) else {
109+ return None ;
110+ } ;
111+
112+ let Some ( status_code) = fields. get ( "status_code" ) else {
113+ return None ;
114+ } ;
115+
116+ let Some ( payload) = fields. get ( "payload" ) else {
117+ return None ;
118+ } ;
119+
120+ let Value {
121+ kind :
122+ Some ( StructValue ( Struct {
123+ fields : header_fields,
124+ } ) ) ,
125+ } = headers
126+ else {
127+ return None ;
128+ } ;
129+ let http_headers: HashMap < String , String > = header_fields
130+ . iter ( )
131+ . filter_map ( |( k, v) | {
132+ let value = match & v. kind {
133+ Some ( Kind :: StringValue ( s) ) if !s. is_empty ( ) => s. clone ( ) ,
134+ _ => return None ,
135+ } ;
136+
137+ Some ( ( k. clone ( ) , value) )
138+ } )
139+ . collect ( ) ;
140+
141+ let json = serde_json:: to_vec_pretty ( & payload) . unwrap_or_else ( |err| {
100142 format ! ( r#"{{"error": "Serialization failed: {}"}}"# , err) . into_bytes ( )
101143 } ) ;
102- Some ( HttpResponse :: ok ( json, HashMap :: new ( ) ) )
144+
145+ let Some ( Kind :: NumberValue ( code) ) = status_code. kind else {
146+ return None ;
147+ } ;
148+ Some ( HttpResponse :: new ( code as u16 , http_headers. clone ( ) , json) )
103149 }
104150 None => Some ( HttpResponse :: internal_server_error (
105151 "Flow execution failed" . to_string ( ) ,
0 commit comments