Skip to content

Commit 92a7f4f

Browse files
Merge pull request spotify#54 from honnix/patch-2
Close response to avoid leaking
2 parents 3b50c92 + 6490b72 commit 92a7f4f

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/main/java/com/spotify/github/v3/clients/GithubPage.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.Optional;
3939
import java.util.concurrent.CompletableFuture;
4040
import java.util.stream.Stream;
41+
import okhttp3.ResponseBody;
4142

4243
/**
4344
* Async page implementation for github resources
@@ -157,13 +158,15 @@ private CompletableFuture<Map<String, Link>> linkMapAsync() {
157158
return github
158159
.request(path)
159160
.thenApply(
160-
response ->
161-
Optional.ofNullable(response.headers().get("Link"))
161+
response -> {
162+
Optional.ofNullable(response.body()).ifPresent(ResponseBody::close);
163+
return Optional.ofNullable(response.headers().get("Link"))
162164
.map(linkHeader -> stream(linkHeader.split(",")))
163165
.orElseGet(Stream::empty)
164166
.map(linkString -> Link.from(linkString.split(";")))
165167
.filter(link -> link.rel().isPresent())
166-
.collect(toMap(link -> link.rel().get(), identity())));
168+
.collect(toMap(link -> link.rel().get(), identity()));
169+
});
167170
}
168171

169172
private Optional<Integer> pageNumberFromUri(final String uri) {

0 commit comments

Comments
 (0)