@@ -177,49 +177,19 @@ AwsSmithyClientBase::BuildHttpRequest(const std::shared_ptr<AwsSmithyClientAsync
177177 return httpRequest;
178178}
179179
180- void AwsSmithyClientBase::MakeRequestAsync (Aws::AmazonWebServiceRequest const * const request,
181- const char * requestName,
182- Aws::Http::HttpMethod method ,
183- EndpointUpdateCallback && endpointCallback ,
184- ResponseHandlerFunc && responseHandler,
185- std::shared_ptr<Aws::Utils::Threading::Executor> pExecutor ) const
180+
181+ bool AwsSmithyClientBase::ResolveIdentityAuth (
182+ std::shared_ptr<AwsSmithyClientAsyncRequestContext>& pRequestCtx ,
183+ ResponseHandlerFunc && responseHandler ,
184+ EndpointUpdateCallback && endpointCallback
185+ ) const
186186{
187- if (!responseHandler)
188- {
189- assert (!" Missing a mandatory response handler!" );
190- AWS_LOGSTREAM_FATAL (AWS_SMITHY_CLIENT_LOG, " Unable to continue AWSClient request: response handler is missing!" );
191- return ;
192- }
193187
194- std::shared_ptr<AwsSmithyClientAsyncRequestContext> pRequestCtx =
195- Aws::MakeShared<AwsSmithyClientAsyncRequestContext>(AWS_SMITHY_CLIENT_LOG);
196- if (!pRequestCtx)
197- {
198- AWS_LOGSTREAM_ERROR (AWS_SMITHY_CLIENT_LOG, " Failed to allocate an AwsSmithyClientAsyncRequestContext under a shared ptr" );
199- auto outcome = HttpResponseOutcome (ClientError (CoreErrors::MEMORY_ALLOCATION, " " , " Failed to allocate async request context" , false /* retryable*/ ));
200- pExecutor->Submit ([outcome, responseHandler]() mutable
201- {
202- responseHandler (std::move (outcome));
203- } );
204- return ;
205- }
206- pRequestCtx->m_pExecutor = pExecutor;
207- pRequestCtx->m_pRequest = request;
208- if (requestName)
209- pRequestCtx->m_requestName = requestName;
210- else if (pRequestCtx->m_pRequest )
211- pRequestCtx->m_requestName = pRequestCtx->m_pRequest ->GetServiceRequestName ();
212- pRequestCtx->m_method = method;
213- pRequestCtx->m_retryCount = 0 ;
214- pRequestCtx->m_invocationId = Aws::Utils::UUID::PseudoRandomUUID ();
215188 auto authSchemeOptionOutcome = this ->SelectAuthSchemeOption (*pRequestCtx);
216189 if (!authSchemeOptionOutcome.IsSuccess ())
217190 {
218- pExecutor->Submit ([authSchemeOptionOutcome, responseHandler]() mutable
219- {
220- responseHandler (std::move (authSchemeOptionOutcome));
221- } );
222- return ;
191+ responseHandler (std::move (authSchemeOptionOutcome));
192+ return false ;
223193 }
224194 pRequestCtx->m_authSchemeOption = std::move (authSchemeOptionOutcome.GetResultWithOwnership ());
225195 assert (pRequestCtx->m_authSchemeOption .schemeId );
@@ -228,26 +198,23 @@ void AwsSmithyClientBase::MakeRequestAsync(Aws::AmazonWebServiceRequest const* c
228198 auto identityOutcome = this ->ResolveIdentity (*pRequestCtx);
229199 if (!identityOutcome.IsSuccess ())
230200 {
231- pExecutor->Submit ([identityOutcome, responseHandler]() mutable
232- {
233- responseHandler (std::move (identityOutcome));
234- });
235- return ;
201+ responseHandler (std::move (identityOutcome));
202+ return false ;
236203 }
204+
237205 pRequestCtx->m_awsIdentity = std::move (identityOutcome.GetResultWithOwnership ());
238206
239207 // get endpoint params from operation context
240208 const auto contextEndpointParameters = this ->GetContextEndpointParameters (*pRequestCtx);
209+
241210 if (!contextEndpointParameters.IsSuccess ())
242211 {
243- pExecutor->Submit ([contextEndpointParameters, responseHandler]() mutable
244- {
245- responseHandler (std::move (contextEndpointParameters.GetError ()));
246- });
247- return ;
212+ responseHandler (std::move (contextEndpointParameters.GetError ()));
213+
214+ return false ;
248215 }
249216
250- Aws::Endpoint::EndpointParameters epParams = request ? request ->GetEndpointContextParams () : Aws::Endpoint::EndpointParameters ();
217+ Aws::Endpoint::EndpointParameters epParams = pRequestCtx-> m_pRequest ? pRequestCtx-> m_pRequest ->GetEndpointContextParams () : Aws::Endpoint::EndpointParameters ();
251218 const auto authSchemeEpParams = pRequestCtx->m_authSchemeOption .endpointParameters ();
252219 epParams.insert (epParams.end (), authSchemeEpParams.begin (), authSchemeEpParams.end ());
253220 const auto contextParams = contextEndpointParameters.GetResult ();
@@ -260,25 +227,63 @@ void AwsSmithyClientBase::MakeRequestAsync(Aws::AmazonWebServiceRequest const* c
260227 epResolutionOutcome.GetError ().GetExceptionName (),
261228 epResolutionOutcome.GetError ().GetMessage (),
262229 false });
263-
264- pExecutor->Submit ([epOutcome, responseHandler]() mutable
265- {
266- responseHandler (std::move (epOutcome));
267- } );
268- return ;
230+ responseHandler (std::move (epOutcome));
231+ return false ;
269232 }
270233 pRequestCtx->m_endpoint = std::move (epResolutionOutcome.GetResultWithOwnership ());
271-
272234 if (!Aws::Utils::IsValidHost (pRequestCtx->m_endpoint .GetURI ().GetAuthority ()))
273235 {
274236 AWS_LOGSTREAM_ERROR (AWS_SMITHY_CLIENT_LOG, " Invalid DNS Label found in URI host" );
275237 auto outcome = HttpResponseOutcome (ClientError (CoreErrors::VALIDATION, " " , " Invalid DNS Label found in URI host" , false /* retryable*/ ));
238+ responseHandler (std::move (outcome));
239+ return false ;
240+ }
241+ return true ;
242+ }
243+
244+ void AwsSmithyClientBase::MakeRequestAsync (Aws::AmazonWebServiceRequest const * const request,
245+ const char * requestName,
246+ Aws::Http::HttpMethod method,
247+ EndpointUpdateCallback&& endpointCallback,
248+ ResponseHandlerFunc&& responseHandler,
249+ std::shared_ptr<Aws::Utils::Threading::Executor> pExecutor) const
250+ {
251+ if (!responseHandler)
252+ {
253+ assert (!" Missing a mandatory response handler!" );
254+ AWS_LOGSTREAM_FATAL (AWS_SMITHY_CLIENT_LOG, " Unable to continue AWSClient request: response handler is missing!" );
255+ return ;
256+ }
257+
258+ std::shared_ptr<AwsSmithyClientAsyncRequestContext> pRequestCtx =
259+ Aws::MakeShared<AwsSmithyClientAsyncRequestContext>(AWS_SMITHY_CLIENT_LOG, request, requestName, pExecutor );
260+ if (!pRequestCtx)
261+ {
262+ AWS_LOGSTREAM_ERROR (AWS_SMITHY_CLIENT_LOG, " Failed to allocate an AwsSmithyClientAsyncRequestContext under a shared ptr" );
263+ auto outcome = HttpResponseOutcome (ClientError (CoreErrors::MEMORY_ALLOCATION, " " , " Failed to allocate async request context" , false /* retryable*/ ));
276264 pExecutor->Submit ([outcome, responseHandler]() mutable
277265 {
278266 responseHandler (std::move (outcome));
279267 } );
280268 return ;
281269 }
270+
271+ pRequestCtx->m_method = method;
272+ ResponseHandlerFunc modifiedResponseHandler = [&](HttpResponseOutcome&& outcome){
273+ auto capturedOutcome = std::make_shared<HttpResponseOutcome>(std::move (outcome));
274+ pExecutor->Submit ([capturedOutcome, &responseHandler]()
275+ {
276+ responseHandler (std::move (*capturedOutcome));
277+ });
278+ };
279+
280+ if (!ResolveIdentityAuth (
281+ pRequestCtx,
282+ std::move (modifiedResponseHandler),
283+ std::move (endpointCallback)))
284+ {
285+ return ;
286+ }
282287 pRequestCtx->m_requestInfo .attempt = 1 ;
283288 pRequestCtx->m_requestInfo .maxAttempts = 0 ;
284289 pRequestCtx->m_interceptorContext = Aws::MakeShared<InterceptorContext>(AWS_SMITHY_CLIENT_LOG, *request);
@@ -682,4 +687,39 @@ void AwsSmithyClientBase::AppendToUserAgent(const Aws::String& valueToAppend)
682687{
683688 assert (m_userAgentInterceptor);
684689 m_userAgentInterceptor->AddLegacyFeaturesToUserAgent (valueToAppend);
690+ }
691+
692+ /*
693+ blocking API to resolve endpoint from request
694+ */
695+ AwsSmithyClientBase::ResolveEndpointOutcome AwsSmithyClientBase::ResolveEndpointFromRequest (
696+ Aws::AmazonWebServiceRequest const * const request,
697+ const char * requestName,
698+ EndpointUpdateCallback&& endpointCallback) const
699+ {
700+ ResolveEndpointOutcome outcome = ClientError (CoreErrors::INTERNAL_FAILURE, " " , " Response handler was not called" , false );
701+ ResponseHandlerFunc responseHandler = [&outcome](HttpResponseOutcome&& asyncOutcome)
702+ {
703+ outcome = std::move (asyncOutcome);
704+ };
705+
706+ std::shared_ptr<AwsSmithyClientAsyncRequestContext> pRequestCtx = Aws::MakeShared<AwsSmithyClientAsyncRequestContext>(AWS_SMITHY_CLIENT_LOG, request, requestName, nullptr );
707+ if (!pRequestCtx)
708+ {
709+ AWS_LOGSTREAM_ERROR (AWS_SMITHY_CLIENT_LOG, " Failed to allocate an AwsSmithyClientAsyncRequestContext under a shared ptr" );
710+ auto result = HttpResponseOutcome (ClientError (CoreErrors::MEMORY_ALLOCATION, " " , " Failed to allocate async request context" , false /* retryable*/ ));
711+ responseHandler (std::move (result));
712+ }
713+ else
714+ {
715+ if (this ->ResolveIdentityAuth (
716+ pRequestCtx,
717+ std::move (responseHandler),
718+ std::move (endpointCallback)
719+ ))
720+ {
721+ outcome = std::move (pRequestCtx->m_endpoint );
722+ }
723+ }
724+ return outcome;
685725}
0 commit comments