Class: Etapper::SessionFilter

Inherits:
SOAP::Filter::StreamHandler
  • Object
show all
Defined in:
lib/etapper/session_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSessionFilter

Returns a new instance of SessionFilter.



8
9
10
# File 'lib/etapper/session_filter.rb', line 8

def initialize
  @cookie_values = {}
end

Instance Attribute Details

Returns the value of attribute cookie_values.



6
7
8
# File 'lib/etapper/session_filter.rb', line 6

def cookie_values
  @cookie_values
end

Instance Method Details

#on_http_inbound(req, res) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/etapper/session_filter.rb', line 28

def on_http_inbound(req, res)
  res.header['Set-Cookie'].each do |cookie|
    value = cookie.sub(/;.*/, '')
    if value =~ /(.*?)\s*=\s*(.*)/
      @cookie_values[$1] = $2
    end
  end
end

#on_http_outbound(req) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/etapper/session_filter.rb', line 12

def on_http_outbound(req)
  if cookies.empty?
    req.header.delete('Cookie')
  else
    req.header['Cookie'] = cookies
  end
  
  # Tweak the XML body to fit eTapestry's quirks and bugs
  b = HTTP::Message::Body.new
  c = req.body.content
  c.gsub!(/>\s*</m,'><')  # Remove whitespace between elements
  c.gsub!(/<(\S+) xsi:nil="true"><\/\1>/,'')  # Strip out elements that are simply nil
  b.init_request(c)
  req.body = b
end