fuel icon indicating copy to clipboard operation
fuel copied to clipboard

GET query parameters are not generated

Open RankoR opened this issue 4 years ago • 3 comments

Bug Report

Description

When I pass parameters to the request, Fuel ignores it.

To Reproduce

Example from the docs:

println(Fuel.get("https://httpbin.org/get", listOf("foo" to "foo", "bar" to "bar")).url.toString())

Outputs:

https://httpbin.org/get

The real use case:

val (_, _, result) = Fuel
                    .get(
                        tokenCheckUrl,
                        listOf("access_token" to it.token)
                    )
                    .also { println(it.url.toString()) }
                    .also { println(it.toString()) }
                    .also { println(it.request.cUrlString()) }
                    .responseString()

Output:

https://www.googleapis.com/oauth2/v3/tokeninfo
--> GET https://www.googleapis.com/oauth2/v3/tokeninfo
Body : (empty)
Headers : (0)
curl -i https://www.googleapis.com/oauth2/v3/tokeninfo

Expected behavior

Query parameters are included in the request.

Environment

Development Machine

  • OS: macOS 10.15.3
  • IDE: IDEA 2020.1
  • Fuel version: 2.2.1
  • Kotlin version: 1.3.71
  • JVM version: 14 (OpenJDK)

RankoR avatar Apr 12 '20 17:04 RankoR

I have tried it locally, with the following code:

fun main() {
    val (_, _, result) = Fuel.get("https://httpbin.org/get", listOf("foo" to "bar")).responseString()

    when (result) {
        is Result.Failure -> throw result.error
        is Result.Success -> println(result.get())
    }
}

And the result I got is this:

{
  "args": {
    "foo": "bar"
  }, 
  "headers": {
    "Accept": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2", 
    "Host": "httpbin.org", 
    "User-Agent": "Java/11.0.6", 
    "X-Amzn-Trace-Id": "Root=1-5e93857c-f87cc6ec5476b00883a30a46"
  }, 
  "origin": "191.162.245.112", 
  "url": "https://httpbin.org/get?foo=bar"
}

Which means the parameters are being correctly sent. I believe when you try to get the url from the request, it is not built with the parameters, since there is a parameters parameter inside the request class:

println(Fuel.get("https://httpbin.org/get", listOf("foo" to "bar")).parameters.toString())

Results in

[(foo, bar)]

lucasqueiroz avatar Apr 12 '20 21:04 lucasqueiroz

Yes, @lucasqueiroz is right here. I do think that the request is being built correctly or else we should have a much bigger problem in the tests. 😸

Do you think this is a problem? @RankoR

kittinunf avatar Apr 14 '20 07:04 kittinunf

Parameters are processed as a middleware. That's why it doesn't show up in .url for example.

https://github.com/kittinunf/fuel/issues/735 has some related information. That wouldn't have been possible otherwise.

SleeplessByte avatar Apr 23 '20 00:04 SleeplessByte