icyleaf/halite

request option values repeated when reusing clients

qszhu opened this issue · 6 comments

qszhu commented

I'm not sure whether this is the expected behavior.

It's normal when not reusing client:

r = Halite.get("http://httpbin.org/get", params: {"foo"=> "bar"})
puts "1st response", r.body

r = Halite.get("http://httpbin.org/get", params: {"foo"=> "bar"})
puts "2nd response", r.body
Output
1st response
{
  "args": {
    "foo": "bar"
  }, 
  "headers": {
    "Accept-Encoding": "gzip, deflate", 
    "Host": "httpbin.org", 
    "User-Agent": "Halite/0.10.0"
  }, 
  "origin": "xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx", 
  "url": "https://httpbin.org/get?foo=bar"
}
2nd response
{
  "args": {
    "foo": "bar"
  }, 
  "headers": {
    "Accept-Encoding": "gzip, deflate", 
    "Host": "httpbin.org", 
    "User-Agent": "Halite/0.10.0"
  }, 
  "origin": "xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx", 
  "url": "https://httpbin.org/get?foo=bar"
}

Reusing with absolute path:

client = Halite::Client.new do
  endpoint "http://httpbin.org"
end

r = client.get("/get", params: {"foo"=> "bar"})
puts "1st response", r.body

r = client.get("/get", params: {"foo"=> "bar"})
puts "2nd response", r.body
Output
1st response
{
  "args": {
    "foo": "bar"
  }, 
  "headers": {
    "Accept-Encoding": "gzip, deflate", 
    "Host": "httpbin.org", 
    "User-Agent": "Halite/0.10.0"
  }, 
  "origin": "xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx", 
  "url": "https://httpbin.org/get?foo=bar"
}
2nd response
{
  "args": {
    "foo": [
      "bar", 
      "bar"
    ]
  }, 
  "headers": {
    "Accept-Encoding": "gzip, deflate", 
    "Host": "httpbin.org", 
    "User-Agent": "Halite/0.10.0"
  }, 
  "origin": "xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx", 
  "url": "https://httpbin.org/get?foo=bar&foo=bar"
}

The query parameters is repeated in this case.

Reusing client with relative path:

r = client.get("get", params: {"foo"=> "bar"})
puts "1st response", r.body

r = client.get("get", params: {"foo"=> "bar"})
puts "2nd response", r.body
Output
1st response
{
  "args": {
    "foo": "bar"
  }, 
  "headers": {
    "Accept-Encoding": "gzip, deflate", 
    "Host": "httpbin.org", 
    "User-Agent": "Halite/0.10.0"
  }, 
  "origin": "xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx", 
  "url": "https://httpbin.org/get?foo=bar"
}
2nd response
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.</p>

I guess the URL path is repeated in this case so 404 is returned.

Found the bug, I will track it down.

Issue 2 was found, but i can not reproduce issue 3 to return 404. would you append logging and resend the result to me?

client = Halite::Client.new do
  endpoint "http://httpbin.org"
  logging "common"  # <- Add this line of code
end
qszhu commented

Here it is.

Code:

require "halite"

client = Halite::Client.new do
  endpoint "http://httpbin.org"
  logging "common"
end

r = client.get("get", params: {"foo"=> "bar"})
r = client.get("get", params: {"foo"=> "bar"})

Output:

2019-05-27 15:10:07 +08:00 | request  | GET    | http://httpbin.org/get?foo=bar
2019-05-27 15:10:07 +08:00 | response | 200    | http://httpbin.org/get?foo=bar | 745.49ms | application/json
{
  "args": {
    "foo": "bar"
  }, 
  "headers": {
    "Accept-Encoding": "gzip, deflate", 
    "Host": "httpbin.org", 
    "User-Agent": "Halite/0.10.0"
  }, 
  "origin": "xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx", 
  "url": "https://httpbin.org/get?foo=bar"
}

2019-05-27 15:10:07 +08:00 | request  | GET    | http://httpbin.org/get/get?foo=bar&foo=bar
2019-05-27 15:10:10 +08:00 | response | 404    | http://httpbin.org/get/get?foo=bar&foo=bar | 2.77s | text/html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.</p>

I think you are the the 0.10.0 tag, try master branch which it fixed it.

qszhu commented

Yes, I can confirm the master branch fixed it. It's all about a shared URI reference. The join method in a previous commit happened to avoid changing the path.

I think it can be closed now. Did you find any other problems so that you reopened it?

That's great!