ahorn / android-rss

Lightweight Android library to parse RSS 2.0 feeds.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using a custom User-Agent

darius-d-e-v opened this issue · comments

I have to use a custom User-Agent string in the request to the server. One way of doing that (I think) would be to pass my own HttpClient to the constructor of RSSReader where I have set the correct user-agent beforehand. The problem is that I have to pass an RSSParser at the same time and I can't seem to use "new RSSParser(new RSSConfig())" from my own code as the RSSParser class is not public.

How about adding a constructor like this to RSSReader.java?

  /**
   * Instantiate a thread-safe HTTP client to retrieve RSS feeds. The injected
   * {@link HttpClient} implementation must be thread-safe.
   * Internal memory consumption and load performance can be tweaked with
   * {@link RSSConfig}.
   * 
   * @param httpclient thread-safe HTTP client implementation
   * @param config RSS configuration
   */
  public RSSReader(HttpClient httpclient, RSSConfig config) {
      this(httpclient, new RSSParser(config));
  }

Then it can be called like this:

  String userAgent = "custom-user-agent";
  AndroidHttpClient httpClient = AndroidHttpClient.newInstance(userAgent);
  RSSConfig rssConfig = new RSSConfig(5, 5);
  RSSReader reader = new RSSReader(httpClient, rssConfig);

Thanks for pointing this out. The suggested change has been implemented:

55aaca8#src/main/java/org/mcsoxford/rss/RSSReader.java