Sha256: 299dcbb0c6f982d8e0b128f46cf81faa3ebb100638c5646c2846c4e827fb69e8

Contents?: true

Size: 847 Bytes

Versions: 1

Compression:

Stored size: 847 Bytes

Contents

module Terminus
  class Proxy

    class External < Rack::Proxy
      attr_reader :uri

      def initialize(uri)
        @uri = uri
      end

      def rewrite_env(env)
        env = env.dup
        env['SERVER_NAME'] = @uri.host
        env['SERVER_PORT'] = @uri.port
        env['HTTP_HOST']   = "#{@uri.host}:#{@uri.port}"
        env.delete('HTTP_ACCEPT_ENCODING')

        if scheme = @uri.scheme
          env['rack.url_scheme'] = scheme
        end

        if %w[PUT POST].include?(env['REQUEST_METHOD'])
          env['CONTENT_LENGTH'] ||= '0'
        end

        env
      end

      def call(env)
        dock_host = env['SERVER_NAME']
        response = super
        response[1].delete('transfer-encoding')
        response[2].extend(Rewrite)
        response[2].dock_host = dock_host
        response
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
terminus-0.5.0 lib/terminus/proxy/external.rb