Class: GrpcKit::Session::Headers

Inherits:
Struct
  • Object
show all
Defined in:
lib/grpc_kit/session/headers.rb

Constant Summary collapse

RESERVED_HEADERS =
[
  'content-type',
  'user-agent',
  'grpc-message-type',
  'grpc-encoding',
  'grpc-message',
  'grpc-status',
  'grpc-status-details-bin',
  'grpc-accept-encoding',
  'te'
].freeze
IGNORE_HEADERS =
[':method', ':scheme'].freeze
METADATA_ACCEPTABLE_HEADER =
%w[:authority user-agent].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHeaders

Returns a new instance of Headers.



33
34
35
# File 'lib/grpc_kit/session/headers.rb', line 33

def initialize
  super({}) # set metadata empty hash
end

Instance Attribute Details

#grpc_encodingObject

Returns the value of attribute grpc_encoding

Returns:

  • (Object)

    the current value of grpc_encoding



7
8
9
# File 'lib/grpc_kit/session/headers.rb', line 7

def grpc_encoding
  @grpc_encoding
end

#grpc_statusObject

Returns the value of attribute grpc_status

Returns:

  • (Object)

    the current value of grpc_status



7
8
9
# File 'lib/grpc_kit/session/headers.rb', line 7

def grpc_status
  @grpc_status
end

#http_statusObject

Returns the value of attribute http_status

Returns:

  • (Object)

    the current value of http_status



7
8
9
# File 'lib/grpc_kit/session/headers.rb', line 7

def http_status
  @http_status
end

#metadataObject

Returns the value of attribute metadata

Returns:

  • (Object)

    the current value of metadata



7
8
9
# File 'lib/grpc_kit/session/headers.rb', line 7

def 
  @metadata
end

#methodObject

Returns the value of attribute method

Returns:

  • (Object)

    the current value of method



7
8
9
# File 'lib/grpc_kit/session/headers.rb', line 7

def method
  @method
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



7
8
9
# File 'lib/grpc_kit/session/headers.rb', line 7

def path
  @path
end

#status_messageObject

Returns the value of attribute status_message

Returns:

  • (Object)

    the current value of status_message



7
8
9
# File 'lib/grpc_kit/session/headers.rb', line 7

def status_message
  @status_message
end

#timeoutObject

Returns the value of attribute timeout

Returns:

  • (Object)

    the current value of timeout



7
8
9
# File 'lib/grpc_kit/session/headers.rb', line 7

def timeout
  @timeout
end

Instance Method Details

#add(key, val) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/grpc_kit/session/headers.rb', line 37

def add(key, val)
  case key
  when ':path'
    self.path = val
  when ':status'
    self.http_status = Integer(val)
  when 'content-type'
    # self.grpc_encoding = val
  when 'grpc-encoding'
    self.grpc_encoding = val
  when 'grpc-status'
    self.grpc_status = val
  when 'grpc-timeout'
    self.timeout = GrpcTime.new(val)
  when 'grpc-message'
    self.status_message = val
  when 'grpc-status-details-bin'
    # TODO
    GrpcKit.logger.warn('grpc-status-details-bin is unsupported header now')
  else
    if IGNORE_HEADERS.include?(key)
      return
    end

    if RESERVED_HEADERS.include?(key) && !METADATA_ACCEPTABLE_HEADER.include?(key)
      return
    end

    [key] = val
  end
end