mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-03-25 08:55:53 +00:00
Restore and improve compatibility with ruby 1.8.
This commit is contained in:
parent
655fc9eb56
commit
6ec66d11ed
3 changed files with 37 additions and 21 deletions
|
|
@ -3,29 +3,12 @@ require 'http/cookie/version'
|
||||||
require 'time'
|
require 'time'
|
||||||
require 'uri'
|
require 'uri'
|
||||||
require 'domain_name'
|
require 'domain_name'
|
||||||
|
require 'http/cookie/ruby_compat'
|
||||||
|
|
||||||
module HTTP
|
module HTTP
|
||||||
autoload :CookieJar, 'http/cookie_jar'
|
autoload :CookieJar, 'http/cookie_jar'
|
||||||
end
|
end
|
||||||
|
|
||||||
# In Ruby < 1.9.3 URI() does not accept a URI object.
|
|
||||||
if RUBY_VERSION < "1.9.3"
|
|
||||||
begin
|
|
||||||
URI(URI(''))
|
|
||||||
rescue
|
|
||||||
def URI(url) # :nodoc:
|
|
||||||
case url
|
|
||||||
when URI
|
|
||||||
url
|
|
||||||
when String
|
|
||||||
URI.parse(url)
|
|
||||||
else
|
|
||||||
raise ArgumentError, 'bad argument (expected URI object or URI string)'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# This class is used to represent an HTTP Cookie.
|
# This class is used to represent an HTTP Cookie.
|
||||||
class HTTP::Cookie
|
class HTTP::Cookie
|
||||||
# Maximum number of bytes per cookie (RFC 6265 6.1 requires 4096 at
|
# Maximum number of bytes per cookie (RFC 6265 6.1 requires 4096 at
|
||||||
|
|
|
||||||
33
lib/http/cookie/ruby_compat.rb
Normal file
33
lib/http/cookie/ruby_compat.rb
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
class Array
|
||||||
|
def select!
|
||||||
|
i = 0
|
||||||
|
each_with_index { |x, j|
|
||||||
|
yield x or next
|
||||||
|
self[i] = x if i != j
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
return nil if i == size
|
||||||
|
self[i..-1] = []
|
||||||
|
self
|
||||||
|
end unless method_defined?(:select!)
|
||||||
|
end
|
||||||
|
|
||||||
|
# In Ruby < 1.9.3 URI() does not accept a URI object.
|
||||||
|
if RUBY_VERSION < "1.9.3"
|
||||||
|
require 'uri'
|
||||||
|
|
||||||
|
begin
|
||||||
|
URI(URI(''))
|
||||||
|
rescue
|
||||||
|
def URI(url) # :nodoc:
|
||||||
|
case url
|
||||||
|
when URI
|
||||||
|
url
|
||||||
|
when String
|
||||||
|
URI.parse(url)
|
||||||
|
else
|
||||||
|
raise ArgumentError, 'bad argument (expected URI object or URI string)'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -255,7 +255,7 @@ class HTTP::CookieJar
|
||||||
db_delete(cookie)
|
db_delete(cookie)
|
||||||
end
|
end
|
||||||
|
|
||||||
def each(uri = nil)
|
def each(uri = nil, &block)
|
||||||
now = Time.now
|
now = Time.now
|
||||||
if uri
|
if uri
|
||||||
@st_cookies_for_domain ||=
|
@st_cookies_for_domain ||=
|
||||||
|
|
@ -304,7 +304,7 @@ class HTTP::CookieJar
|
||||||
yield cookie
|
yield cookie
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
@sjar.each(uri, &proc)
|
@sjar.each(uri, &block)
|
||||||
else
|
else
|
||||||
@st_all_cookies ||=
|
@st_all_cookies ||=
|
||||||
@db.prepare(<<-'SQL')
|
@db.prepare(<<-'SQL')
|
||||||
|
|
@ -333,7 +333,7 @@ class HTTP::CookieJar
|
||||||
|
|
||||||
yield cookie
|
yield cookie
|
||||||
}
|
}
|
||||||
@sjar.each(&proc)
|
@sjar.each(&block)
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue