Proposal: Net::HTTP user-agent class for Ruby stdlib

drbrain | Mon, 25 Jul 2011 19:36:58 GMT

Posted in

I have proposed adding a new class to Ruby's standard library that makes Net::HTTP easier to use. You can read my HTTP user-agent class proposal on redmine.

The first question is not "What should the API look like?" but "Should it be in the standard library?". My argument is this:

I have had discussions where people say "Net::HTTP's API is not very good" and people seem to want a better way to use Net::HTTP without trying out one of the many Net::HTTP::Agent-like extensions to the base API.

Having a recommended way to perform HTTP access in ruby will be useful to the community since they don't have to do any additional research. Also users will be able perform basic HTTP requests for multiple servers and will gain the efficiencies of persistent connections without extra work.

The biggest issue people have is that they need to pass the host, port and SSL params for every HTTP connection made. The nature of the API means that most people make a new connection for every request. Since this is confusing for new users and annoying for experienced users I think it should be addressed in stdlib.

Do you think a smoother API for performing HTTP requests would be useful in Ruby's standard library? If you do (or don't) I'd appreciate further discussion on the ticket. comments

Comments RSS FEED

i always have to take a look at the documentation for net/http. even for simple get requests. it’s annoying. so yes … please add a simple interface for executing http requests to the stdlib!

daniel harrington said about 2 hours later

After getting to know the Net::HTTP API, I found it to be not that bad, but definitely not perfect. After working with the API in ronin-support and Spidr, here are some things that I found lacking:

  • No single Object/Class/variable to describe a HTTP Proxy.
  • No way to perform requests entirely via option Hashes.
  • Will not auto-parse Strings into URIs.
  • No way to easily convert a Hash of Symbols => Strings into canonical Headers.
  • No easy way to do generic requests (a :method option would be nice).
  • net-http-persistent should be built-in.
  • No Authentication cache.
  • No optional redirect following.
  • Bad handling of Timeouts. Sometimes I want to instantly fail, other times I might want to instantly retry.
  • Bad handling of Proxy timeouts / persistent connections.
  • Namespacing: Net::HTTP is a class and Net::HTTPRequest is polluting the Net namespace.
Postmodern said about 6 hours later

I’m not a fan of the Net::HTTP API and I like your proposal for an Agent class, but I don’t think it should be added to the stdlib.

I’d rather see it available as a gem – stdlib is where good libraries go to stagnate.

James Healy said 1 day later

It depends upon the maintainer whether the library stagnates or not. I’ve taken RDoc from stagnation to maintained and continue to maintain RDoc. I’ve breathed new life into rake as well.

There are other libraries not maintained by me that have had important improvements made that aren’t necessarily visible. net/http and net/https were merged in Ruby 1.9 and Net::IMAP gained several new capabilities.

With the upcoming gemification of the standard library this should become less of a problem.

I don’t think “it might stagnate” is a good reason to avoid the inclusion. While updates may be slower on a ruby release cycle, my proposal is meant to provide a better base for building fancier libraries that have special needs, not to fulfill everyone’s wishes.

Eric Hodel said 1 day later

With the upcoming gemification of the standard library

James Healy said 3 days later

Comments are disabled