Changeset 17505 in josm for trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java
- Timestamp:
- 2021-02-21T13:23:35+01:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java
r16692 r17505 135 135 return false; // do no try to load data from no-tile at zoom, cache empty object instead 136 136 } 137 if (isNotImage(headers, statusCode)) { 138 String message = detectErrorMessage( new String(content, StandardCharsets.UTF_8)); 139 if (message != null && !message.isEmpty()) { 140 tile.setError(message); 141 } 142 return false; 143 } 137 144 return super.isResponseLoadable(headers, statusCode, content); 138 145 } 139 146 140 @Override 141 protected boolean cacheAsEmpty() { 142 return isNoTileAtZoom() || super.cacheAsEmpty(); 147 private boolean isNotImage(Map<String, List<String>> headers, int statusCode) { 148 if (statusCode == 200 && headers.containsKey("Content-Type") && !headers.get("Content-Type").isEmpty()) { 149 String contentType = headers.get("Content-Type").stream().findAny().get(); 150 if (contentType !=null && !contentType.startsWith("image")) { 151 Logging.warn("Image not returned for tile: " + url + " content type was: " + contentType); 152 // not an image - do not store response in cache, so next time it will be queried again from the server 153 return true; 154 } 155 } 156 return false; 157 } 158 159 @Override 160 protected boolean cacheAsEmpty(Map<String, List<String>> headerFields, int responseCode) { 161 if (isNotImage(headerFields, responseCode)) { 162 return false; 163 } 164 return isNoTileAtZoom() || super.cacheAsEmpty(headerFields, responseCode); 143 165 } 144 166 … … 211 233 212 234 private void handleError(CacheEntryAttributes attributes) { 235 if (tile.hasError() && tile.getErrorMessage() != null) { 236 // tile has already set error message, don't overwrite it 237 return; 238 } 213 239 if (attributes != null) { 214 240 int httpStatusCode = attributes.getResponseCode();
Note:
See TracChangeset
for help on using the changeset viewer.