Skip to content

Commit

Permalink
Added SessionCache#active?.
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Feb 28, 2010
1 parent ca20696 commit 730e09f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/spidr/session_cache.rb
Expand Up @@ -33,6 +33,27 @@ def initialize(proxy=Spidr.proxy)
@sessions = {}
end

#
# Determines if there is an active HTTP session for a given URL.
#
# @param [URI::HTTP, String] url
# The URL that represents a session.
#
# @return [Boolean]
# Specifies whether there is an active HTTP session.
#
# @since 0.2.3
#
def active?(url)
# normalize the url
url = URI(url.to_s) unless url.kind_of?(URI)

# session key
key = [url.scheme, url.host, url.port]

return @sessions.has_key?(key)
end

#
# Provides an active HTTP session for a given URL.
#
Expand All @@ -46,6 +67,7 @@ def [](url)
# normalize the url
url = URI(url.to_s) unless url.kind_of?(URI)

# session key
key = [url.scheme, url.host, url.port]

unless @sessions[key]
Expand Down

0 comments on commit 730e09f

Please sign in to comment.