Q: "Best Way" to Add Cookies Support to Net::HTTP Requests?

Hello,

   I maintain (voluntarily without pay for years now)
   the (open source) pluto feed reader / planet [1] that runs Planet
OpenStreeMap, Open SuSe, KDE, and others.

   Yesterday Planet Neuroscience opened this support ticket (on github):

   Feeds requiring cookie support [1]

   Background: The pluto feed reader uses the standard ruby Net::HTTP module
   (via the fetcher gem that handles caching and redirects but no cookies yet).

   Now the question: What's the "best way" to add cookies support to
the standard ruby
    Net::HTTP module? What's your recommendation? Tips? Tricks?

   Happy networking programming with ruby. Cheers. Prost.

[1] Planet Pluto · GitHub
[2] Feeds requiring cookie support · Issue #39 · feedreader/pluto · GitHub

Hi,

If you require an http client with cookie support, there are a few options
available. I maintain httpx, which ships with a cookies plugin:

There are other options: httprb provides also support for cookies, as well
as mechanized, however I cant say anything about overall state of
maintenance.

If you want to stick with net-http and hack your cookie management around
it, you probably want to have a look at http-cookie. My recommendation is
always to pick a client which makes your life easier and does the hard
things for you.

escreveu:

···

A sábado, 7 de ago de 2021, 09:45, Gerald Bauer <gerald.bauer@gmail.com>

Hello,

   I maintain (voluntarily without pay for years now)
   the (open source) pluto feed reader / planet [1] that runs Planet
OpenStreeMap, Open SuSe, KDE, and others.

   Yesterday Planet Neuroscience opened this support ticket (on github):

   Feeds requiring cookie support [1]

   Background: The pluto feed reader uses the standard ruby Net::HTTP
module
   (via the fetcher gem that handles caching and redirects but no cookies
yet).

   Now the question: What's the "best way" to add cookies support to
the standard ruby
    Net::HTTP module? What's your recommendation? Tips? Tricks?

   Happy networking programming with ruby. Cheers. Prost.

[1] Planet Pluto · GitHub
[2] Feeds requiring cookie support · Issue #39 · feedreader/pluto · GitHub

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<ruby-talk list: member options login page>

Hello,

   First thanks for your outstanding work on HTTPX [1] - a more modern
HTTP library.

   And thanks for the great advice and recommendations on handling cookies.

  Unfortunately the feed fetcher HTTP code is an almost 10-year old beast
   with some specific feed fetching conditional HTTP caching needs e.g.

cache_entry = cache[ uri.to_s ]
if cache_entry
  logger.info "found cache entry for >#{uri.to_s}<"
  if cache_entry['etag']
   logger.info "adding header If-None-Match (etag)
> #{cache_entry['etag']}< for conditional GET"

   headers['If-None-Match'] = cache_entry['etag']
  end
  if cache_entry['last-modified']
  logger.info "adding header If-Modified-Since (last-modified)
> #{cache_entry['last-modified']}< for conditional GET"

  headers['If-Modified-Since'] = cache_entry['last-modified']
  end
end
...

  and, thus, for now I rather add another little patch for adding
cookies "by hand".

  For sure long-term the plan is to use a more modern HTTP library
and, yes, the idea of the fetcher gem from the very start was to make
the fetching pluggable and easily configurable. Again thanks for
your great advice and recommendations.

  Cheers. Prost.

[1] HoneyryderChuck / httpx · GitLab
[2] webclient/worker.rb at master · rubycoco/webclient · GitHub