Sha256: 78b5ee4b0d06fece4de5997f0bc040c5c3d518ee6730a6e3be7a125f600a19c8

Contents?: true

Size: 633 Bytes

Versions: 66

Compression:

Stored size: 633 Bytes

Contents

module Pact
  module Consumer
    class CorsOriginHeaderMiddleware

      def initialize app, cors_enabled
        @app = app
        @cors_enabled = cors_enabled
      end

      def call env
        response = @app.call env
        if env['HTTP_X_PACT_MOCK_SERVICE'] || @cors_enabled
          add_cors_header env, response
        else
          response
        end
      end

      def shutdown
        @app.shutdown
      end

      private

      def add_cors_header env, response
        [response[0], response[1].merge('Access-Control-Allow-Origin' => env.fetch('HTTP_ORIGIN','*')), response[2]]
      end
    end
  end
end

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
pact-mock_service-3.5.0 lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
pact-mock_service-3.4.0 lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
pact-mock_service-3.3.1 lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
pact-mock_service-3.3.0 lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
pact-mock_service-3.2.1 lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
pact-mock_service-3.2.0 lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
pact-mock_service-3.1.1 lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
pact-mock_service-3.1.0 lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
pact-mock_service-3.0.1 lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
pact-mock_service-3.0.0 lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
pact-mock_service-2.12.0 lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
pact-mock_service-2.11.0 lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
pact-mock_service-2.10.1 lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
pact-mock_service-2.10.0 lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
pact-mock_service-2.9.8 lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
pact-mock_service-2.9.3 lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
pact-mock_service-2.9.2 lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
pact-mock_service-2.9.1 lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
pact-mock_service-2.9.0 lib/pact/consumer/mock_service/cors_origin_header_middleware.rb
pact-mock_service-2.8.1 lib/pact/consumer/mock_service/cors_origin_header_middleware.rb