Pkmmte / PkRSS

A powerful RSS feed manager for Android
Apache License 2.0
100 stars 23 forks source link

OkHttpDownloader encodes path incorrectly when paging #18

Closed dharrigan closed 2 years ago

dharrigan commented 8 years ago

Hi,

If I have a URI of the form:

http://foo.bar.com/news?format=rss

and I'm hitting a new page (i.e., page > 1), then the resulting URL ends up as:

http://foo.bar.com/news?format=rss?paged=2

This causes the request to fail.

I've re-written the method (using Kotlin - but I'm sure should be easy enough to convert to Java), that uses the inbuilt URI builder to cope with query parameters.

import android.content.Context
import android.net.Uri
import com.pkmmte.pkrss.Request
import com.pkmmte.pkrss.downloader.OkHttpDownloader

class CorrectedOkHttpDownloader(context: Context) : OkHttpDownloader(context) {

  override fun toUrl(request: Request): String {

        var uriBuilder = Uri.parse(request.url).buildUpon()

        if (request.individual) {
            uriBuilder
                    .appendPath("feed")
                    .appendQueryParameter("withoutcomments", "1")
        } else {
            if (request.search != null) {
                uriBuilder.appendQueryParameter("s", Uri.encode(request.search))
            }
            if (request.page > 1) {
                val page = request.page
                uriBuilder.appendQueryParameter("paged", "$page")
            }           
        }

        return uriBuilder.build().toString()

    }

}

Hope this helps!

-=david=-

Pkmmte commented 8 years ago

Thank you for your contribution! I'll be implementing something similar to this in the upcoming version.

dharrigan commented 8 years ago

Awesome! Thank you! :-)

-=david=-