Skip to content

Commit 78c20fe

Browse files
committed
Check if transfer-Encoding header is set, if so the response has a body
1 parent 0430499 commit 78c20fe

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

kafka-connect-fitbit-source/src/main/java/org/radarbase/connect/rest/fitbit/user/ServiceUserRepository.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,10 @@ class ServiceUserRepository : UserRepository {
240240
): T = withContext(Dispatchers.IO) {
241241
val response = client.request(builder)
242242
val contentLength = response.contentLength()
243-
val hasBody = contentLength != null && contentLength > 0
243+
// if Transfer-Encoding: chunked, then the request has data but contentLength will be null.
244+
val transferEncoding = response.headers["Transfer-Encoding"]
245+
val hasBody = (contentLength != null && contentLength > 0) ||
246+
(transferEncoding != null && transferEncoding.contains("chunked"))
244247
if (response.status == HttpStatusCode.NotFound) {
245248
throw NoSuchElementException("URL " + response.request.url + " does not exist")
246249
} else if (!response.status.isSuccess() || !hasBody) {

0 commit comments

Comments
 (0)