@@ -2,19 +2,19 @@ use std::sync::Arc;
22
33use async_trait:: async_trait;
44use error_stack:: { Report , ResultExt } ;
5- use fastly:: http:: { header, Method } ;
5+ use fastly:: http:: { header, HeaderValue } ;
66use fastly:: { Request , Response } ;
77use serde:: { Deserialize , Serialize } ;
88use serde_json:: { Map , Value } ;
99use validator:: Validate ;
1010
11- use crate :: backend:: ensure_backend_from_url;
1211use crate :: constants:: { HEADER_SYNTHETIC_FRESH , HEADER_SYNTHETIC_TRUSTED_SERVER } ;
1312use crate :: error:: TrustedServerError ;
1413use crate :: integrations:: {
1514 AttributeRewriteAction , IntegrationAttributeContext , IntegrationAttributeRewriter ,
1615 IntegrationEndpoint , IntegrationProxy , IntegrationRegistration ,
1716} ;
17+ use crate :: proxy:: { proxy_request, ProxyRequestConfig } ;
1818use crate :: settings:: { IntegrationConfig as IntegrationConfigTrait , Settings } ;
1919use crate :: synthetic:: { generate_synthetic_id, get_or_generate_synthetic_id} ;
2020use crate :: tsjs;
@@ -143,20 +143,20 @@ impl IntegrationProxy for TestlightIntegration {
143143
144144 payload. user . id = Some ( synthetic_id. clone ( ) ) ;
145145
146- let mut upstream = Request :: new ( Method :: POST , self . config . endpoint . clone ( ) ) ;
147- upstream. set_header ( header:: CONTENT_TYPE , "application/json" ) ;
148- upstream
149- . set_body_json ( & payload)
146+ let payload_bytes = serde_json:: to_vec ( & payload)
150147 . change_context ( Self :: error ( "Failed to serialize request body" ) ) ?;
151148
152- if let Some ( user_agent) = req. get_header ( header:: USER_AGENT ) {
153- upstream. set_header ( header:: USER_AGENT , user_agent) ;
154- }
149+ let mut proxy_config = ProxyRequestConfig :: new ( & self . config . endpoint ) ;
150+ proxy_config. forward_synthetic_id = false ;
151+ proxy_config. body = Some ( payload_bytes) ;
152+ proxy_config. stream_passthrough = true ;
153+ proxy_config. headers . push ( (
154+ header:: CONTENT_TYPE ,
155+ HeaderValue :: from_static ( "application/json" ) ,
156+ ) ) ;
155157
156- let backend = ensure_backend_from_url ( & self . config . endpoint )
157- . change_context ( Self :: error ( "Failed to determine backend" ) ) ?;
158- let mut response = upstream
159- . send ( backend)
158+ let mut response = proxy_request ( settings, req, proxy_config)
159+ . await
160160 . change_context ( Self :: error ( "Failed to contact upstream integration" ) ) ?;
161161
162162 // Attempt to parse response into structured form for logging/future transforms.
0 commit comments