Merge pull request #8385 from nextcloud/fix-is-internet-walled-check

Fix ConnectivityService.isInternetWalled() check when content length is -1
This commit is contained in:
Tobias Kaminsky 2021-05-18 07:18:56 +02:00 committed by GitHub
commit 3c6415147b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -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();

View file

@ -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)