@@ -3,11 +3,10 @@ use std::sync::Arc;
33use crate :: executors:: common:: HttpExecutionResponse ;
44use crate :: executors:: dedupe:: { request_fingerprint, ABuildHasher , SharedResponse } ;
55use async_trait:: async_trait;
6- use aws_sigv4:: http_request:: {
7- sign, SignableBody , SignableRequest , SigningParams ,
8- } ;
96use dashmap:: DashMap ;
107use hive_router_config:: HiveRouterConfig ;
8+ use reqsign_aws_v4:: Credential ;
9+ use reqsign_core:: Signer ;
1110use tokio:: sync:: OnceCell ;
1211
1312use bytes:: { BufMut , Bytes , BytesMut } ;
@@ -39,7 +38,7 @@ pub struct HTTPSubgraphExecutor {
3938 pub semaphore : Arc < Semaphore > ,
4039 pub config : Arc < HiveRouterConfig > ,
4140 pub in_flight_requests : Arc < DashMap < u64 , Arc < OnceCell < SharedResponse > > , ABuildHasher > > ,
42- pub aws_signing_params : Option < Arc < SigningParams < ' static > > > ,
41+ pub aws_sigv4_signer : Option < Signer < Credential > > ,
4342}
4443
4544const FIRST_VARIABLE_STR : & [ u8 ] = b",\" variables\" :{" ;
@@ -55,7 +54,7 @@ impl HTTPSubgraphExecutor {
5554 semaphore : Arc < Semaphore > ,
5655 config : Arc < HiveRouterConfig > ,
5756 in_flight_requests : Arc < DashMap < u64 , Arc < OnceCell < SharedResponse > > , ABuildHasher > > ,
58- aws_signing_params : Option < Arc < SigningParams < ' static > > > ,
57+ aws_sigv4_signer : Option < Signer < Credential > > ,
5958 ) -> Self {
6059 let mut header_map = HeaderMap :: new ( ) ;
6160 header_map. insert (
@@ -75,7 +74,7 @@ impl HTTPSubgraphExecutor {
7574 semaphore,
7675 config,
7776 in_flight_requests,
78- aws_signing_params ,
77+ aws_sigv4_signer ,
7978 }
8079 }
8180
@@ -138,51 +137,6 @@ impl HTTPSubgraphExecutor {
138137 Ok ( body)
139138 }
140139
141- async fn sign_awssigv4 < ' a > (
142- & self ,
143- req : & ' a mut http:: Request < Full < Bytes > > ,
144- body : & ' a [ u8 ] ,
145- ) -> Result < ( ) , SubgraphExecutorError > {
146- if let Some ( signing_params) = & self . aws_signing_params {
147- let signable_request = SignableRequest :: new (
148- req. method ( ) . as_str ( ) ,
149- req. uri ( ) . to_string ( ) ,
150- req. headers ( ) . iter ( ) . map ( |( k, v) | {
151- (
152- k. as_str ( ) ,
153- str:: from_utf8 ( v. as_bytes ( ) )
154- . map_err ( |err| {
155- SubgraphExecutorError :: AwsSigV4SigningFailure (
156- self . subgraph_name . to_string ( ) ,
157- err. to_string ( ) ,
158- )
159- } )
160- . unwrap ( ) ,
161- )
162- } ) ,
163- SignableBody :: Bytes ( body) ,
164- )
165- . map_err ( |err| {
166- SubgraphExecutorError :: AwsSigV4SigningFailure (
167- self . subgraph_name . to_string ( ) ,
168- err. to_string ( ) ,
169- )
170- } ) ?;
171-
172- let ( signing_instructions, _) = sign ( signable_request, & signing_params)
173- . map_err ( |err| {
174- SubgraphExecutorError :: AwsSigV4SigningFailure (
175- self . subgraph_name . to_string ( ) ,
176- err. to_string ( ) ,
177- )
178- } ) ?
179- . into_parts ( ) ;
180-
181- signing_instructions. apply_to_request_http1x ( req) ;
182- }
183- Ok ( ( ) )
184- }
185-
186140 async fn _send_request (
187141 & self ,
188142 body : Vec < u8 > ,
@@ -192,19 +146,26 @@ impl HTTPSubgraphExecutor {
192146 . method ( http:: Method :: POST )
193147 . uri ( & self . endpoint )
194148 . version ( Version :: HTTP_11 )
195- . body ( Default :: default ( ) )
149+ . body ( Full :: new ( Bytes :: from ( body ) ) )
196150 . map_err ( |e| {
197151 SubgraphExecutorError :: RequestBuildFailure ( self . endpoint . to_string ( ) , e. to_string ( ) )
198152 } ) ?;
199153
200154 * req. headers_mut ( ) = headers;
201155
202- self . sign_awssigv4 ( & mut req, & body) . await ?;
203-
204- * req. body_mut ( ) = Full :: new ( Bytes :: from ( body) ) ;
205-
206156 debug ! ( "making http request to {}" , self . endpoint. to_string( ) ) ;
207157
158+ if let Some ( aws_sigv4_signer) = & self . aws_sigv4_signer {
159+ let ( mut parts, body) = req. into_parts ( ) ;
160+ aws_sigv4_signer. sign ( & mut parts, None ) . await . map_err ( |e| {
161+ SubgraphExecutorError :: AwsSigV4SigningFailure (
162+ self . endpoint . to_string ( ) ,
163+ e. to_string ( ) ,
164+ )
165+ } ) ?;
166+ req = http:: Request :: from_parts ( parts, body) ;
167+ }
168+
208169 let res = self . http_client . request ( req) . await . map_err ( |e| {
209170 SubgraphExecutorError :: RequestFailure ( self . endpoint . to_string ( ) , e. to_string ( ) )
210171 } ) ?;
0 commit comments