Sha256: 8cbc1617b7b842d13258508dd05b37ca2786ccd724d6f46df30ea2fd1cab2acb

Contents?: true

Size: 976 Bytes

Versions: 4

Compression:

Stored size: 976 Bytes

Contents

# frozen_string_literal: true

require 'eac_envs/http/request'
require 'eac_ruby_utils/core_ext'
require 'webrick'

module EacEnvs
  module Http
    module Rspec
      class EchoServer
        class RequestProcessor
          REQUEST_TO_DATA = {
            ssl: :ssl?,
            method: :request_method,
            uri: :unparsed_uri,
            body: :body
          }.freeze

          common_constructor :request, :response

          def perform
            response.body = response_body
            response.header['Content-type'] = 'application/json'
            response.status = 200
          end

          def request_data
            REQUEST_TO_DATA.transform_values { |v| request.send(v) }.merge(headers: request_headers)
          end

          def request_headers
            request.header.transform_values(&:first)
          end

          def response_body
            ::JSON.generate(request_data)
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
eac_envs-http-0.6.1 lib/eac_envs/http/rspec/echo_server/request_processor.rb
eac_envs-http-0.6.0 lib/eac_envs/http/rspec/echo_server/request_processor.rb
eac_envs-http-0.5.1 lib/eac_envs/http/rspec/echo_server/request_processor.rb
eac_envs-http-0.5.0 lib/eac_envs/http/rspec/echo_server/request_processor.rb