Class: PermessageDeflate::ClientSession

Inherits:
Session
  • Object
show all
Defined in:
lib/permessage_deflate/client_session.rb

Constant Summary

Constants inherited from Session

Session::MAX_WINDOW_BITS, Session::MIN_WINDOW_BITS, Session::VALID_PARAMS, Session::VALID_WINDOW_BITS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Session

#close, #initialize, #process_incoming_message, #process_outgoing_message

Constructor Details

This class inherits a constructor from PermessageDeflate::Session

Class Method Details

.valid_params?(params) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
12
# File 'lib/permessage_deflate/client_session.rb', line 4

def self.valid_params?(params)
  return false unless super

  if params.has_key?('client_max_window_bits')
    return false unless VALID_WINDOW_BITS.include?(params['client_max_window_bits'])
  end

  true
end

Instance Method Details

#activate(params) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/permessage_deflate/client_session.rb', line 44

def activate(params)
  return false unless ClientSession.valid_params?(params)

  if @accept_max_window_bits and params['client_max_window_bits']
    return false if params['client_max_window_bits'] > @accept_max_window_bits
  end

  if @request_no_context_takeover and !params['server_no_context_takeover']
    return false
  end

  if @request_max_window_bits
    return false unless params['server_max_window_bits']
    return false if params['server_max_window_bits'] > @request_max_window_bits
  end

  @own_context_takeover = !(@accept_no_context_takeover || params['client_no_context_takeover'])
  @own_window_bits = [
    @accept_max_window_bits || MAX_WINDOW_BITS,
    params['client_max_window_bits'] || MAX_WINDOW_BITS
  ].min

  @peer_context_takeover = !params['server_no_context_takeover']
  @peer_window_bits = params['server_max_window_bits'] || MAX_WINDOW_BITS

  true
end

#generate_offerObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/permessage_deflate/client_session.rb', line 14

def generate_offer
  offer = {}

  if @accept_no_context_takeover
    offer['client_no_context_takeover'] = true
  end

  if @accept_max_window_bits
    unless VALID_WINDOW_BITS.include?(@accept_max_window_bits)
      raise ConfigurationError, 'Invalid value for max_window_bits'
    end
    offer['client_max_window_bits'] = @accept_max_window_bits
  else
    offer['client_max_window_bits'] = true
  end

  if @request_no_context_takeover
    offer['server_no_context_takeover'] = true
  end

  if @request_max_window_bits
    unless VALID_WINDOW_BITS.include?(@request_max_window_bits)
      raise ConfigurationError, 'Invalid value for request_max_window_bits'
    end
    offer['server_max_window_bits'] = @request_max_window_bits
  end

  offer
end