Sha256: 10f96700d4e16f04d45dcc0d32815490c5c84fb2a350055db411992bac55e177

Contents?: true

Size: 1.01 KB

Versions: 16

Compression:

Stored size: 1.01 KB

Contents

class Rack::App::Endpoint::Catcher

  def initialize(app, endpoint_properties)
    @app = app
    @endpoint_properties = endpoint_properties
  end

  def call(env)
    resp = handle_rack_response do
      handle_response_body(env) do
        @app.call(env)
      end
    end
    return resp.finish if resp.is_a?(Rack::Response)

    resp
  end

  protected

  def handle_rack_response
    catch(:rack_response) { return yield }.finish
  end

  def handle_response_body(env)
    body = catch(:response_body) { return yield }
    request_handler = env[Rack::App::Constants::ENV::HANDLER]
    set_response_body(request_handler, body)
    throw :rack_response, request_handler.response
  end

  EXTNAME = ::Rack::App::Constants::ENV::EXTNAME

  def set_response_body(handler, response_body)
    extname = handler.request.env[EXTNAME]
    handler.response.headers.merge!(@endpoint_properties.serializer.response_headers_for(extname))
    handler.response.write(@endpoint_properties.serializer.serialize(extname, response_body))
  end

end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
rack-app-11.0.2 lib/rack/app/endpoint/catcher.rb
rack-app-11.0.1 lib/rack/app/endpoint/catcher.rb
rack-app-11.0.0 lib/rack/app/endpoint/catcher.rb
rack-app-10.0.0 lib/rack/app/endpoint/catcher.rb
rack-app-9.0.0 lib/rack/app/endpoint/catcher.rb
rack-app-8.1.0 lib/rack/app/endpoint/catcher.rb
rack-app-8.0.1 lib/rack/app/endpoint/catcher.rb
rack-app-8.0.0 lib/rack/app/endpoint/catcher.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/rack-app-7.7.0/lib/rack/app/endpoint/catcher.rb
rack-app-7.7.0 lib/rack/app/endpoint/catcher.rb
rack-app-7.6.5 lib/rack/app/endpoint/catcher.rb
rack-app-7.6.4 lib/rack/app/endpoint/catcher.rb
rack-app-7.6.3 lib/rack/app/endpoint/catcher.rb
rack-app-7.6.2 lib/rack/app/endpoint/catcher.rb
rack-app-7.6.1 lib/rack/app/endpoint/catcher.rb
rack-app-7.6.0 lib/rack/app/endpoint/catcher.rb