Class: GrpcKit::Session::Headers

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

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initializeHeaders

Returns a new instance of Headers.



18
19
20
21
# File 'lib/grpc_kit/session/headers.rb', line 18

def initialize
  @opts = {}
  @metadata = {}
end

Instance Method Details

#add(key, val) ⇒ void

This method returns an undefined value.

Parameters:

  • key (String)
  • val (String)


73
74
75
# File 'lib/grpc_kit/session/headers.rb', line 73

def add(key, val)
  @opts[key] = val
end

#content_typeString?

Returns:

  • (String, nil)


51
52
53
# File 'lib/grpc_kit/session/headers.rb', line 51

def content_type
  @opts['content-type']
end

#grpc_encodingString?

Returns:

  • (String, nil)


46
47
48
# File 'lib/grpc_kit/session/headers.rb', line 46

def grpc_encoding
  @opts['grpc-encoding']
end

#grpc_statusString?

Returns:

  • (String, nil)


41
42
43
# File 'lib/grpc_kit/session/headers.rb', line 41

def grpc_status
  @opts['grpc-status']
end

#http_statusString?

Returns:

  • (String, nil)


66
67
68
# File 'lib/grpc_kit/session/headers.rb', line 66

def http_status
  @opts[':status']
end

#metadataHash<String,String>

Returns:

  • (Hash<String,String>)


24
25
26
27
28
29
30
31
32
33
# File 'lib/grpc_kit/session/headers.rb', line 24

def 
  @metadata =
    if @metadata.empty?
      @opts.select do |key|
        !key.start_with?(':', 'grpc-') && !RESERVED_HEADERS.include?(key)
      end
    else
      @metadata
    end
end

#pathString?

Returns:

  • (String, nil)


36
37
38
# File 'lib/grpc_kit/session/headers.rb', line 36

def path
  @opts[':path']
end

#status_messageString?

Returns:

  • (String, nil)


56
57
58
# File 'lib/grpc_kit/session/headers.rb', line 56

def status_message
  @opts['grpc-message']
end

#timeoutTime?

Returns:

  • (Time, nil)


61
62
63
# File 'lib/grpc_kit/session/headers.rb', line 61

def timeout
  @timeout ||= @opts['grpc-timeout'] && GrpcTime.new(@opts['grpc-timeout'])
end