Skip to content
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
import java.net.http.HttpResponse;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Collections;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -280,14 +283,20 @@ private FlagConfigResponse handleFlagConfigurationSuccess(final HttpResponse<Str
* @return Date - the parsed Last-Modified date, or null if not present or parsing fails
*/
private Date extractLastUpdatedFromHeaders(final HttpResponse<String> response) {
Optional<String> headerOpt = response.headers()
.firstValue(Const.HTTP_HEADER_LAST_MODIFIED);
if (!headerOpt.isPresent()) {
log.debug("Last-Modified header is not present in the response");
return null;
}
String headerValue = headerOpt.get();
try {
String headerValue = response.headers()
.firstValue(Const.HTTP_HEADER_LAST_MODIFIED)
.orElse(null);
SimpleDateFormat lastModifiedHeaderFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
return headerValue != null ? lastModifiedHeaderFormatter.parse(headerValue) : null;
} catch (Exception e) {
log.debug("Error parsing Last-Modified header: {}", e.getMessage());
return Date.from(
ZonedDateTime.parse(headerValue, DateTimeFormatter.RFC_1123_DATE_TIME)
.toInstant()
);
} catch (DateTimeParseException e) {
log.debug("Failed to parse Last-Modified header: '{}'. Cause: {}", headerValue, e.getMessage());
return null;
}
}
Expand Down
Loading