5656# Use Mocking to re-route requests to 169.254.169.254 without having to actually start an
5757# HTTP.jl server. Should result in faster running tests.
5858function _imds_patch (
59- router:: HTTP.Router = HTTP. Router (); listening= true , enabled= true ,
59+ router:: HTTP.Router = HTTP. Router ();
60+ listening= true ,
61+ enabled= true ,
6062 num_requests:: Threads.Atomic{Int} = Threads. Atomic {Int} (),
6163)
6264 num_requests[] = 0
6365
6466 patch = @patch function HTTP. request (
65- method, url, headers= [], body= HTTP. nobody; status_exception= true , retry:: Bool = true ,
66- retries:: Int = 4 , retry_delays= ExponentialBackOff (; n= retries, factor= 3 ),
67- retry_check= (args... ) -> false , kwargs...
67+ method,
68+ url,
69+ headers= [],
70+ body= HTTP. nobody;
71+ status_exception= true ,
72+ retry:: Bool = true ,
73+ retries:: Int = 4 ,
74+ retry_delays= ExponentialBackOff (; n= retries, factor= 3 ),
75+ retry_check= (args... ) -> false ,
76+ kwargs... ,
6877 )
6978 uri = HTTP. URI (url)
7079 if uri. host != " 169.254.169.254"
@@ -88,26 +97,25 @@ function _imds_patch(
8897 # When `status_exception=false` retries do not occur as an exception needs to
8998 # be raised for them to work. This replicates how `HTTP.request` works.
9099 if status_exception && resp. status >= 300
91- ex = HTTP. Exceptions. StatusError (
92- resp. status, req. method, req. target, resp
93- )
100+ ex = HTTP. Exceptions. StatusError (resp. status, req. method, req. target, resp)
94101 throw (ex)
95102 end
96103 return resp
97104 end
98105
99106 retry_request = Base. retry (
100- handler,
107+ handler;
101108 delays= retry_delays,
102109 check= (s, ex) -> begin
103110 resp_body = get (req. context, :response_body , nothing )
104111 resp = ! isnothing (resp_body) ? req. response : nothing
105112 retry = (
106- (HTTP. RetryRequest. isrecoverable (ex) && HTTP. retryable (req)) ||
107- (HTTP. retryablebody (req) && retry_check (s, ex, req, resp, resp_body))
113+ (HTTP. RetryRequest. isrecoverable (ex) && HTTP. retryable (req)) || (
114+ HTTP. retryablebody (req) && retry_check (s, ex, req, resp, resp_body)
115+ )
108116 )
109117 return retry
110- end
118+ end ,
111119 )
112120
113121 return retry_request (req)
187195 io_error = Base. IOError (" read: connection timed out (ETIMEDOUT)" , - 110 )
188196 throw (HTTP. Exceptions. RequestError (request, io_error))
189197 end
190- router = Router ([
191- Route (" PUT" , " /latest/api/token" , connection_timeout),
192- ])
198+ router = Router ([Route (" PUT" , " /latest/api/token" , connection_timeout)])
193199 apply (_imds_patch (router)) do
194200 # Set some initial values so we can tell what gets modified
195201 session = IMDS. Session (" bar" , - 1 , - 1 )
203209 end
204210
205211 # IMDSv1 is available
206- router = Router ([response_route (" PUT" , " /latest/api/token" , HTTP. Response (404 ))])
212+ router = Router ([
213+ response_route (" PUT" , " /latest/api/token" , HTTP. Response (404 ))
214+ ])
207215 apply (_imds_patch (router)) do
208216 # Set some initial values so we can tell what gets modified
209217 session = IMDS. Session (" bar" , - 1 , - 1 )
0 commit comments