Skip to content

Commit 170dca9

Browse files
committed
Added Metadata inner class to retrieve the response headers
1 parent 87e8572 commit 170dca9

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

azd/src/main/java/org/azd/utils/RestClient.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.azd.utils;
22

3+
import org.azd.common.types.BaseAbstractMethod;
34
import org.azd.connection.Connection;
45
import org.azd.enums.ApiExceptionTypes;
56
import org.azd.enums.CustomHeader;
@@ -11,6 +12,7 @@
1112
import java.net.http.HttpRequest;
1213
import java.net.http.HttpResponse;
1314
import java.util.Map;
15+
import java.util.Optional;
1416
import java.util.OptionalLong;
1517
import java.util.concurrent.CompletableFuture;
1618

@@ -26,7 +28,7 @@ public abstract class RestClient {
2628
* can be checked after every request, but we don't want to have to modify all the existing API methods
2729
* to return the data.
2830
*
29-
* We need this to bw able to check if we are near any API rate limits - as creating 20+ releases in
31+
* We need this to be able to check if we are near any API rate limits - as creating 20+ releases in
3032
* a short time can cause one to go over the limit and even have requests fail.
3133
*/
3234
static HttpHeaders headersFromLastRequest = null;
@@ -42,6 +44,16 @@ static OptionalLong retryAfterInterval() {
4244
return OptionalLong.empty();
4345
}
4446

47+
/**
48+
* Metadata class to retrieve the response headers. This separates the implementation and
49+
* retrieval from the RestClient adapter class.
50+
*/
51+
public static final class Metadata {
52+
public static String getResponseHeader(String value) {
53+
return RestClient.headersFromLastRequest.firstValue(value).orElse("");
54+
}
55+
}
56+
4557
/**
4658
* Request the Azure DevOps REST API and builds the request url dynamically based on resource id and endpoints passed
4759
*

0 commit comments

Comments
 (0)