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


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


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

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

#content_typeString?


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

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

#grpc_encodingString?


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

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

#grpc_statusString?


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

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

#http_statusString?


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

def http_status
  @opts[':status']
end

#metadataHash<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?


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

def path
  @opts[':path']
end

#status_messageString?


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

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

#timeoutTime?


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

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