Sha256: 8ad8330f2ac8e8d0d78efad0701316ec8537abf497f9c5513057bce3dfc74c56

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

require 'grpc_kit/session/duration'

module GrpcKit
  module Session
    Headers = Struct.new(
      :metadata,
      :path,
      :grpc_encoding,
      :grpc_status,
      :status_message,
      :timeout,
      :method,
      :http_status,
    ) do

      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
      def initialize
        super({}) # set metadata empty hash
      end

      def add(key, val)
        case key
        when ':path'
          self.path = val
        when ':status'
          self.http_status = Integer(val)
        when 'content-type'
          # TODO
          metadata[key] = val
        when 'grpc-encoding'
          self.grpc_encoding = val
        when 'grpc-status'
          self.grpc_status = val
        when 'grpc-timeout'
          self.timeout = Duration.decode(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 RESERVED_HEADERS.include?(key) && !METADATA_ACCEPTABLE_HEADER.include?(key)
            return
          end

          metadata[key] = val
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grpc_kit-0.1.3 lib/grpc_kit/session/headers.rb