PiRSquared17 / ttrss-reader-fork

Automatically exported from code.google.com/p/ttrss-reader-fork
0 stars 1 forks source link

Server-local cached images cannot be downloaded when HTTP Authentication is in use #269

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I couldn't figure out how to reopen bug 164. :) So, I'll submit a new issue...

The problem is that when the images are cached by the ttrss server itself, and 
http auth is in use, the image fetching lacks the authorization to correctly 
download.

For example, if the ttrss server is located at https://exmaple.com/tt-rss/ and 
has feeds configured to cache locally (Edit feed / Options / Cache images 
locally), then the images will be loaded from 
https://example.com/tt-rss/image.php?hash=nnnnn...

When http authentication is used to reach https://exmaple.com/tt-rss/, the 
image fetches to https://example.com/tt-rss/image.php?hash=nnnnn... currently 
lack the required Authorization header.

I think something like this is needed in 
ttrssreader/src/main/java/org/ttrssreader/utils/FileUtils.java, in class 
FileUtils, in downloadToFile, just after this code happens:

    URL url = new URL(downloadUrl);
    URLConnection connection = url.openConnection();

I think something like the following is needed:

    Controller controller = Controller.getInstance();

    if (downloadUrl.startsWith(controller.url()) &&
        controller.useHttpAuth()) {

        String httpUsername = controller.httpUsername();
        String httpPassword = controller.httpPassword();

        String auth = Base64.encodeToString((httpUsername + ":" + httpPassword).getBytes("UTF-8"), Base64.NO_WRAP)

        connection.setRequestProperty("Authorization", "Basic " + auth);
    }

(This is based on code from net/JavaJSONConnector.java.)

Additionally, I couldn't tell if downloadToFile was the only way images were 
fetched, though.

Thanks!

Original issue reported on code.google.com by plus.goo...@influx.outflux.net on 7 Feb 2015 at 8:23

GoogleCodeExporter commented 9 years ago
(gah, I typoed "example" and "exmaple". The example URLs should all be 
example.com. Sorry!)

Original comment by plus.goo...@influx.outflux.net on 7 Feb 2015 at 8:25