@Override
  public Optional<SensorCacheData> load() {
    String url = URL + "?project=" + project.key();
    if (branchConfiguration.referenceBranchName() != null) {
      url = url + "&branch=" + branchConfiguration.referenceBranchName();
    }

    Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
    GetRequest request = new GetRequest(url).setHeader(ACCEPT_ENCODING, "gzip");

    try (WsResponse response = wsClient.call(request); InputStream is = response.contentStream()) {
      Optional<String> contentEncoding = response.header(CONTENT_ENCODING);
      Optional<Integer> length = response.header(CONTENT_LENGTH).map(Integer::parseInt);
      boolean hasGzipEncoding = contentEncoding.isPresent() && contentEncoding.get().equals("gzip");

      SensorCacheData cache = hasGzipEncoding ? decompress(is) : read(is);
      if (length.isPresent()) {
        profiler.stopInfo(LOG_MSG + String.format(" (%s)", humanReadableByteCountSI(length.get())));
      } else {
        profiler.stopInfo(LOG_MSG);
      }
      return Optional.of(cache);
    } catch (HttpException e) {
      if (e.code() == 404) {
        profiler.stopInfo(LOG_MSG + " (404)");
        return Optional.empty();
      }
      throw MessageException.of("Failed to download analysis cache: " + DefaultScannerWsClient.createErrorMessage(e));
    } catch (Exception e) {
      throw new IllegalStateException("Failed to download analysis cache", e);
    }
  }
@Test
  public void returns_empty_if_404() {
    when(wsClient.call(any())).thenThrow(new HttpException("url", 404, "content"));
    assertThat(loader.load()).isEmpty();
    assertThat(logs.logs()).anyMatch(s -> s.startsWith("Load analysis cache (404) | time="));
  }