1+ # this is used to allow custom dispatches to `_http_request`
2+ abstract type AbstractBackend end
3+
4+ """
5+ AWS.HTTPBackend <: AWS.AbstractBackend
6+
7+ An `HTTPBackend` can hold default `http_options::AbstractDict{Symbol,<:Any}`
8+ to pass to HTTP.jl, which can be overwritten per-request by any `http_options`
9+ supplied there.
10+ """
11+ struct HTTPBackend{T<: AbstractDict{Symbol,<:Any} } <: AbstractBackend
12+ http_options:: T
13+ end
14+
15+ HTTPBackend () = HTTPBackend (LittleDict {Symbol,String} ())
16+
17+ const DEFAULT_BACKEND = Ref {Union{Nothing, AbstractBackend}} (HTTPBackend ())
18+
119Base. @kwdef mutable struct Request
220 service:: String
321 api_version:: String
@@ -13,6 +31,7 @@ Base.@kwdef mutable struct Request
1331 http_options:: AbstractDict{Symbol,<:Any} = LittleDict {Symbol,String} ()
1432 return_raw:: Bool = false
1533 response_dict_type:: Type{<:AbstractDict} = LittleDict
34+ backend:: AbstractBackend = DEFAULT_BACKEND[]
1635end
1736
1837
@@ -54,7 +73,7 @@ function submit_request(aws::AbstractAWSConfig, request::Request; return_headers
5473 @repeat 3 try
5574 credentials (aws) === nothing || sign! (aws, request)
5675
57- response = @mock _http_request (request)
76+ response = @mock _http_request (request. backend, request )
5877
5978 if response. status in REDIRECT_ERROR_CODES
6079 if HTTP. header (response, " Location" ) != " "
@@ -141,7 +160,9 @@ function submit_request(aws::AbstractAWSConfig, request::Request; return_headers
141160end
142161
143162
144- function _http_request (request:: Request )
163+ function _http_request (http_backend:: HTTPBackend , request:: Request )
164+ http_options = merge (http_backend. http_options, request. http_options)
165+
145166 @repeat 4 try
146167 http_stack = HTTP. stack (redirect= false , retry= false , aws_authorization= false )
147168
@@ -157,7 +178,7 @@ function _http_request(request::Request)
157178 request. content;
158179 require_ssl_verification= false ,
159180 response_stream= request. response_stream,
160- request . http_options...
181+ http_options...
161182 )
162183 catch e
163184 # Base.IOError is needed because HTTP.jl can often have errors that aren't
0 commit comments