diff --git a/src/main/java/com/nextcloud/client/network/ConnectivityServiceImpl.java b/src/main/java/com/nextcloud/client/network/ConnectivityServiceImpl.java index 11548d2778..abdefec1f2 100644 --- a/src/main/java/com/nextcloud/client/network/ConnectivityServiceImpl.java +++ b/src/main/java/com/nextcloud/client/network/ConnectivityServiceImpl.java @@ -74,7 +74,8 @@ class ConnectivityServiceImpl implements ConnectivityService { int status = get.execute(client); - boolean result = !(status == HttpStatus.SC_NO_CONTENT && get.getResponseContentLength() == 0); + // Content-Length is not available when using chunked transfer encoding, so check for -1 as well + boolean result = !(status == HttpStatus.SC_NO_CONTENT && get.getResponseContentLength() <= 0); get.releaseConnection(); diff --git a/src/test/java/com/nextcloud/client/network/ConnectivityServiceTest.kt b/src/test/java/com/nextcloud/client/network/ConnectivityServiceTest.kt index bccd92a686..55cfacfca8 100644 --- a/src/test/java/com/nextcloud/client/network/ConnectivityServiceTest.kt +++ b/src/test/java/com/nextcloud/client/network/ConnectivityServiceTest.kt @@ -276,6 +276,12 @@ class ConnectivityServiceTest { assertFalse(connectivityService.isInternetWalled) } + @Test + fun `status 204 and no content length means internet is not walled`() { + mockResponse(contentLength = -1, status = HttpStatus.SC_NO_CONTENT) + assertFalse(connectivityService.isInternetWalled) + } + @Test fun `other status than 204 means internet is walled`() { mockResponse(contentLength = 0, status = HttpStatus.SC_GONE)