Modifying CGI::Cookie

One of the well-known benefits of Ruby is it allows you to modify any class at any time. This recently became invaluable for a project at work. We use an authentication product from Netegrity that operates at the web server level. However, a problem came up with the Red Hat Linux client. When SiteMinder (the product) updates its cookie, it does not strip whitespace between cookie names. So every 30 seconds the "SMSESSION=value; _session_id=value;" cookie would be sent in the request header as "[space]_session_id=value; SMESSSION=value;"

When this header gets passed to CGI::Cookie::parse, the method splits it with: /[;,]\s?/ Because the space is at the beginning of the string, the cookie name is set as "[space]_session_id" instead of "_session_id" and a new Rails session gets created.

The fix is simple:
class << CGI::Cookie
  alias :parse_without_strip :parse
  def parse(raw_cookie)
    parse_without_strip(raw_cookie ? raw_cookie.strip : raw_cookie)
  end
end

With many other languages, we might have needed to make our own cookie class. And then make own own request class to use our cookie class. Whatever effort it would have taken, it could not be simpler than the fix in Ruby.