Return to Snippet

Revision: 62404
at February 21, 2013 06:32 by mightybs


Initial Code
# ActionController has a cookie "fix" supposedly for performance on ruby < 1.8.1
    # but it's too strict in its parsing and doesn't work with some broken proxies.
    # Sadly the CGI::Cookie provided with ruby 1.8.4 does not suffer this limitation
    # but since it differs in other ways we'll not use it here and just "fix" the rails "fix".

    # check that the parser is broken before overwriting
    if CGI::Cookie.parse('foo=1;bar=2; baz=3')['foo'][0] == '1;bar=2'
      class CGI
        class Cookie
          class << self
            alias_method :strict_parse, :parse
            def parse(raw_cookie)
              # rfc 6265 says "; " separator but some proxies chew my cookies
              raw_cookie &&= raw_cookie.gsub(/;([^ ])/, '; \1')
              strict_parse(raw_cookie)
            end
          end
        end
      end
    end

Initial URL


Initial Description
Working on the problem described here: http://forums.att.com/t5/Data-Messaging-Features-Internet/3G-proxy-wnsnet-attws-com-strips-HTTP-response-headers/m-p/3294533/highlight/false#M59737

After some testing we found the below code to fix our troubles in Rails 1.0 sites.  I have not checked if future Rails versions provide the same "fix" or not.  We include this file in our environment file so that on load of the application we decide whether or not it is necessary and define the fix then.

Initial Title
Rails fix for cookie munging AT&T Proxies

Initial Tags
rails, ruby

Initial Language
Rails