55
66import smithy_core
77from smithy_core .interceptors import Interceptor , InterceptorContext
8+ from smithy_core .types import PropertyKey
89from smithy_http import Field
910from smithy_http .aio .interfaces import HTTPRequest
1011from smithy_http .user_agent import UserAgent , UserAgentComponent
1112
13+ USER_AGENT = PropertyKey (key = "user_agent" , value_type = UserAgent )
14+
1215
1316class UserAgentInterceptor (Interceptor [Any , None , HTTPRequest , None ]):
1417 """Adds interceptors that initialize UserAgent in the context and add the user-agent
@@ -17,12 +20,12 @@ class UserAgentInterceptor(Interceptor[Any, None, HTTPRequest, None]):
1720 def read_before_execution (
1821 self , context : InterceptorContext [Any , None , None , None ]
1922 ) -> None :
20- context .properties ["user_agent" ] = _UserAgentBuilder .from_environment ().build ()
23+ context .properties [USER_AGENT ] = _UserAgentBuilder .from_environment ().build ()
2124
2225 def modify_before_signing (
2326 self , context : InterceptorContext [Any , None , HTTPRequest , None ]
2427 ) -> HTTPRequest :
25- user_agent = context .properties ["user_agent" ]
28+ user_agent = context .properties [USER_AGENT ]
2629 request = context .transport_request
2730 request .fields .set_field (Field (name = "User-Agent" , values = [str (user_agent )]))
2831 return context .transport_request
0 commit comments