-
Notifications
You must be signed in to change notification settings - Fork 2.2k
App Config - Head Requests #48899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
App Config - Head Requests #48899
Changes from all commits
f0f853a
9eb86c5
563120e
aeea5e9
3aa352f
4bb915d
1df33d1
cd19e9d
2a4a7af
0de3c3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,22 +15,27 @@ | |
| import com.azure.core.util.Context; | ||
| import com.azure.core.util.CoreUtils; | ||
| import com.azure.core.util.logging.ClientLogger; | ||
| import com.azure.data.appconfiguration.implementation.models.CheckKeyValuesHeaders; | ||
| import com.azure.data.appconfiguration.implementation.models.KeyValue; | ||
| import com.azure.data.appconfiguration.implementation.models.SnapshotUpdateParameters; | ||
| import com.azure.data.appconfiguration.implementation.models.UpdateSnapshotHeaders; | ||
| import com.azure.data.appconfiguration.models.ConfigurationSetting; | ||
| import com.azure.data.appconfiguration.models.ConfigurationSnapshot; | ||
| import com.azure.data.appconfiguration.models.ConfigurationSnapshotStatus; | ||
| import com.azure.data.appconfiguration.models.SettingFields; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| import java.net.URLDecoder; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
|
|
||
| import reactor.core.publisher.Mono; | ||
|
|
||
| /** | ||
| * App Configuration Utility methods, use internally. | ||
| */ | ||
|
|
@@ -44,6 +49,7 @@ public class Utility { | |
| public static final String NAME = "name"; | ||
| public static final String PARAMETERS = "parameters"; | ||
| public static final String URI = "uri"; | ||
| private static final String AFTER_TAG = "after="; | ||
|
|
||
| /** | ||
| * Represents any value in Etag. | ||
|
|
@@ -210,4 +216,70 @@ public static List<String> getTagsFilterInString(Map<String, String> tagsFilter) | |
| } | ||
| return tagsFilters; | ||
| } | ||
|
|
||
| // Parse the 'after' query parameter value from the Link header. | ||
| // Link header format: </kv?api-version=2023-10-01&$Select=&after=a2V5MTg4Cg%3D%3D>; rel="next" | ||
|
Comment on lines
+220
to
+221
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need a new parse method for
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something about how the Java stuff is built makes this part be built into how the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I follow. There is a |
||
| private static String parseAfterParam(String linkHeader) { | ||
| String nextLink = parseNextLink(linkHeader); | ||
| if (nextLink == null) { | ||
| return null; | ||
| } | ||
| int queryStart = nextLink.indexOf('?'); | ||
| if (queryStart == -1) { | ||
| return null; | ||
| } | ||
| for (String param : nextLink.substring(queryStart + 1).split("&")) { | ||
| if (param.startsWith(AFTER_TAG)) { | ||
| try { | ||
| return URLDecoder.decode(param.substring(AFTER_TAG.length()), StandardCharsets.UTF_8.name()); | ||
| } catch (java.io.UnsupportedEncodingException e) { | ||
| // UTF-8 is always supported | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| // Convert a HEAD response to a PagedResponse with empty items. | ||
| public static PagedResponse<ConfigurationSetting> | ||
| toHeadPagedResponse(ResponseBase<CheckKeyValuesHeaders, Void> response) { | ||
| String continuationToken = parseAfterParam(response.getHeaders().getValue(HttpHeaderName.LINK)); | ||
| return new PagedResponseBase<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), | ||
| Collections.emptyList(), continuationToken, null); | ||
| } | ||
|
|
||
| // Handle 304 status code from HEAD request to a valid response - Async handler | ||
| public static Mono<PagedResponse<ConfigurationSetting>> | ||
| handleHeadNotModifiedErrorToValidResponse(HttpResponseException error) { | ||
| HttpResponse httpResponse = error.getResponse(); | ||
| if (httpResponse == null) { | ||
| return Mono.error(error); | ||
| } | ||
|
|
||
| String continuationToken = parseAfterParam(httpResponse.getHeaderValue(HttpHeaderName.LINK)); | ||
| if (httpResponse.getStatusCode() == 304) { | ||
| return Mono.just(new PagedResponseBase<>(httpResponse.getRequest(), httpResponse.getStatusCode(), | ||
| httpResponse.getHeaders(), Collections.emptyList(), continuationToken, null)); | ||
| } | ||
|
|
||
| return Mono.error(error); | ||
| } | ||
|
|
||
| // Handle 304 status code from HEAD request to a valid response - Sync handler | ||
| public static PagedResponse<ConfigurationSetting> | ||
| handleHeadNotModifiedErrorToValidResponse(HttpResponseException error, ClientLogger logger) { | ||
| HttpResponse httpResponse = error.getResponse(); | ||
| if (httpResponse == null) { | ||
| throw logger.logExceptionAsError(error); | ||
| } | ||
|
|
||
| String continuationToken = parseAfterParam(httpResponse.getHeaderValue(HttpHeaderName.LINK)); | ||
| if (httpResponse.getStatusCode() == 304) { | ||
| return new PagedResponseBase<>(httpResponse.getRequest(), httpResponse.getStatusCode(), | ||
| httpResponse.getHeaders(), Collections.emptyList(), continuationToken, null); | ||
| } | ||
|
|
||
| throw logger.logExceptionAsError(error); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.