1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-31 20:52:13 +01:00

Code reformat

This commit is contained in:
Mattia Bertorello 2019-07-03 18:06:16 +02:00
parent 1bc994ec86
commit f2a4ea5e15
No known key found for this signature in database
GPG Key ID: CE1FB2BE91770F24
3 changed files with 25 additions and 20 deletions

View File

@ -26,15 +26,19 @@ public class CacheControl {
Matcher matcher = PATTERN.matcher(value); Matcher matcher = PATTERN.matcher(value);
while (matcher.find()) { while (matcher.find()) {
switch (matcher.group(1).toLowerCase()) { switch (matcher.group(1).toLowerCase()) {
case "max-age": case "max-age":
cc.setMaxAge(Integer.parseInt(matcher.group(3))); break; cc.setMaxAge(Integer.parseInt(matcher.group(3)));
case "must-revalidate": break;
cc.setMustRevalidate(true); break; case "must-revalidate":
case "no-cache": cc.setMustRevalidate(true);
cc.setNoCache(true); break; break;
case "no-store": case "no-cache":
cc.setNoStore(true); break; cc.setNoCache(true);
default: //ignore break;
case "no-store":
cc.setNoStore(true);
break;
default: //ignore
} }
} }
} }

View File

@ -93,16 +93,16 @@ public class FileDownloaderCache {
if (fileCachedOpt.isChange() || !enableCache) { if (fileCachedOpt.isChange() || !enableCache) {
// Update remote etag and cache control header // Update remote etag and cache control header
return FileDownloaderCache.updateCacheInfo(remoteURL, (remoteETagClean, cacheControl) -> { return FileDownloaderCache.updateCacheInfo(remoteURL, (remoteETagClean, cacheControl) -> {
// Check cache control data // Check cache control data
if (cacheControl.isNoCache() || cacheControl.isMustRevalidate() || cacheControl.isNoStore()) { if (cacheControl.isNoCache() || cacheControl.isMustRevalidate() || cacheControl.isNoStore()) {
log.warn("The file {} must not be cache due to cache control header {}", log.warn("The file {} must not be cache due to cache control header {}",
remoteURL, cacheControl); remoteURL, cacheControl);
return Optional.empty(); return Optional.empty();
} }
fileCachedOpt.setLastETag(remoteETagClean); fileCachedOpt.setLastETag(remoteETagClean);
fileCachedOpt.setCacheControl(cacheControl); fileCachedOpt.setCacheControl(cacheControl);
return Optional.of(fileCachedOpt); return Optional.of(fileCachedOpt);
}); });
} }
return Optional.of(fileCachedOpt); return Optional.of(fileCachedOpt);
} }

View File

@ -67,7 +67,8 @@ public class HttpConnectionManager {
public HttpURLConnection makeConnection() public HttpURLConnection makeConnection()
throws IOException, NoSuchMethodException, ScriptException, URISyntaxException { throws IOException, NoSuchMethodException, ScriptException, URISyntaxException {
return makeConnection(this.requestURL, 0, (c) -> {}); return makeConnection(this.requestURL, 0, (c) -> {
});
} }
private HttpURLConnection makeConnection(URL requestURL, int movedTimes, private HttpURLConnection makeConnection(URL requestURL, int movedTimes,
@ -102,7 +103,7 @@ public class HttpConnectionManager {
beforeConnection.accept(connection); beforeConnection.accept(connection);
// Connect // Connect
log.info("Connect to {}, method={}, request id={}", requestURL, connection.getRequestMethod(),requestId); log.info("Connect to {}, method={}, request id={}", requestURL, connection.getRequestMethod(), requestId);
connection.connect(); connection.connect();
int resp = connection.getResponseCode(); int resp = connection.getResponseCode();
@ -110,7 +111,7 @@ public class HttpConnectionManager {
requestURL, connection.getRequestMethod(), resp, requestId, StringUtils.join(connection.getHeaderFields())); requestURL, connection.getRequestMethod(), resp, requestId, StringUtils.join(connection.getHeaderFields()));
if (resp == HttpURLConnection.HTTP_MOVED_PERM if (resp == HttpURLConnection.HTTP_MOVED_PERM
|| resp == HttpURLConnection.HTTP_MOVED_TEMP) { || resp == HttpURLConnection.HTTP_MOVED_TEMP) {
URL newUrl = new URL(connection.getHeaderField("Location")); URL newUrl = new URL(connection.getHeaderField("Location"));
log.info("The response code was a 301,302 so try again with the new URL " + newUrl); log.info("The response code was a 301,302 so try again with the new URL " + newUrl);