@@ -188,6 +188,7 @@ internal class HttpClient(
188
188
httpResponse = con.responseCode
189
189
190
190
val retryAfter = retryAfterFromResponse(con)
191
+ val retryLimit = retryLimitFromResponse(con)
191
192
val newDelayUntil = _time .currentTimeMillis + (retryAfter ? : 0 ) * 1_000
192
193
if (newDelayUntil > delayNewRequestsUntil) delayNewRequestsUntil = newDelayUntil
193
194
@@ -204,7 +205,7 @@ internal class HttpClient(
204
205
)
205
206
206
207
// TODO: SHOULD RETURN OK INSTEAD OF NOT_MODIFIED TO MAKE TRANSPARENT?
207
- retVal = HttpResponse (httpResponse, cachedResponse, retryAfterSeconds = retryAfter)
208
+ retVal = HttpResponse (httpResponse, cachedResponse, retryAfterSeconds = retryAfter, retryLimit = retryLimit )
208
209
}
209
210
HttpURLConnection .HTTP_ACCEPTED , HttpURLConnection .HTTP_CREATED , HttpURLConnection .HTTP_OK -> {
210
211
val inputStream = con.inputStream
@@ -233,7 +234,7 @@ internal class HttpClient(
233
234
}
234
235
}
235
236
236
- retVal = HttpResponse (httpResponse, json, retryAfterSeconds = retryAfter)
237
+ retVal = HttpResponse (httpResponse, json, retryAfterSeconds = retryAfter, retryLimit = retryLimit )
237
238
}
238
239
else -> {
239
240
Logging .debug(" HttpClient: Got Response = ${method ? : " GET" } ${con.url} - FAILED STATUS: $httpResponse " )
@@ -254,7 +255,7 @@ internal class HttpClient(
254
255
Logging .warn(" HttpClient: Got Response = $method - STATUS: $httpResponse - No response body!" )
255
256
}
256
257
257
- retVal = HttpResponse (httpResponse, jsonResponse, retryAfterSeconds = retryAfter)
258
+ retVal = HttpResponse (httpResponse, jsonResponse, retryAfterSeconds = retryAfter, retryLimit = retryLimit )
258
259
}
259
260
}
260
261
} catch (t: Throwable ) {
@@ -294,6 +295,19 @@ internal class HttpClient(
294
295
}
295
296
}
296
297
298
+ /* *
299
+ * Reads the HTTP Retry-Limit from the response.
300
+ */
301
+ private fun retryLimitFromResponse (con : HttpURLConnection ): Int? {
302
+ val retryLimitStr = con.getHeaderField(" Retry-Limit" )
303
+ return if (retryLimitStr != null ) {
304
+ Logging .debug(" HttpClient: Response Retry-After: $retryLimitStr " )
305
+ retryLimitStr.toIntOrNull()
306
+ } else {
307
+ null
308
+ }
309
+ }
310
+
297
311
private fun logHTTPSent (
298
312
method : String? ,
299
313
url : URL ,
0 commit comments