public static Single<Document> getResponseDocument(final Single<Response> response) {
        return response.flatMap((Function<Response, Single<Document>>) resp -> {
            try {
                final String uri = resp.request().url().toString();
                if (resp.isSuccessful()) {
                    final MediaType mediaType = MediaType.parse(resp.header("content-type", ""));
                    if (mediaType == null || !StringUtils.equals(mediaType.type(), "text") || !StringUtils.equals(mediaType.subtype(), "html")) {
                        throw new IOException("unable to parse non HTML page with media type " + mediaType + " for " + uri);
                    }
                    final InputStream inputStream = resp.body().byteStream();
                    try {
                        return Single.just(Jsoup.parse(inputStream, null, uri));
                    } finally {
                        IOUtils.closeQuietly(inputStream);
                        resp.close();
                    }
                }
                throw new IOException("unsuccessful request " + uri);
            } catch (final Throwable t) {
                return Single.error(t);
            }
        });
    }
Get the HTML document corresponding to the body of a HTTP response.

@param response a HTTP response
@return a Single containing a document corresponding to the body if the response comes from a
successful HTTP request with Content-Type "text/html", or containing an IOException otherwise.
main/src/main/java/cgeo/geocaching/network/Network.java