taf2 / curb

Ruby bindings for libcurl
Other
1.29k stars 229 forks source link

Add `CURLOPT_COOKIELIST` support #455

Closed uvlad7 closed 1 month ago

uvlad7 commented 2 months ago

Add interface to call curl_easy_setopt - Easy::setopt - with CURLOPT_COOKIELIST.

It's not something like #cookielist=, because I believe this method should be more Rubyish, like add constants for special values, support array argument, or even use CURB_OBJECT_HSETTER instead of simply passing it to libcurl and keep it consistent with other options (like you do this with headers=/CURLOPT_HTTPHEADER, for example, and set enable_cookies flag accordingly). All of this requires much more effort, and I'm happy with this simple raw interface.

taf2 commented 2 months ago

Thanks for adding this and agreed with approach would probably like more things to just be handled through the simpler set/get approach. Do you think it would be possible to add to this a test case?

uvlad7 commented 2 months ago

add to this a test case

Sure, gonna take some time, though. Are you OK wit httpbin usage in the test?

taf2 commented 2 months ago

httpbin looks interesting, but we have TestServlet already in the test_helper I assume for testing if cookies are set you could add a new endpoint:

  def do_GET(req,res)
    if req.path.match(/redirect$/)
      res.status = 302
      res['Location'] = '/foo'
    elsif req.path.match(/not_here$/)
      res.status = 404
    elsif req.path.match(/error$/)
      res.status = 500
    end
    respond_with("GET#{req.query_string}",req,res)
  end

Maybe something like:

elsif req.path.match(/test_cookies/)
uvlad7 commented 2 months ago

Added tests. Looks like tests/bug_issue277.rb file is missing and was removed after rake package.

Can you please release a new version after this is merged?

taf2 commented 1 month ago

Thanks this is great !

uvlad7 commented 1 month ago

@taf2 can you please release a new version?