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',
  'te'
].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.



30
31
32
# File 'lib/grpc_kit/session/headers.rb', line 30

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



34
35
36
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
# File 'lib/grpc_kit/session/headers.rb', line 34

def add(key, val)
  case key
  when ':path'
    self.path = val
  when ':status'
    self.http_status = val.to_i
  when 'content-type'
    # TODO
    [key] = val
  when 'grpc-encoding'
    self.grpc_encoding = val
  when 'grpc-status'
    self.grpc_status = val.to_i
  when 'grpc-timeout'
    self.timeout = Duration.decode(val)
  when 'grpc-message'
    # TODO
    GrpcKit.logger.warn('grpc-message is unsupported header now')
  when 'grpc-status-details-bin'
    # TODO
    GrpcKit.logger.warn('grpc-status-details-bin is unsupported header now')
  else
    if RESERVED_HEADERS.include?(key) && !METADATA_ACCEPTABLE_HEADER.include?(key)
      return
    end

    [key] = val
  end
end