Sha256: 4f6afb6d6b3c2e82ca4cab8ca2007a720350fc50dce4cbaeac41843c8d287938

Contents?: true

Size: 493 Bytes

Versions: 9

Compression:

Stored size: 493 Bytes

Contents

# A simple file server middleware
class Simple::Httpd::Rack::Merger
  Rack = Simple::Httpd::Rack

  # returns an app that merges other apps
  def self.build(apps)
    return apps.first if apps.length == 1

    new(apps)
  end

  private

  def initialize(apps)
    @apps = apps
  end

  public

  def call(env)
    @apps.each do |app|
      status, body, headers = app.call(env)
      return [status, body, headers] unless status == 404
    end

    Rack.error 404, "No such action"
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
simple-httpd-0.4.3 lib/simple/httpd/rack/merger.rb
simple-httpd-0.4.2 lib/simple/httpd/rack/merger.rb
simple-httpd-0.4.1 lib/simple/httpd/rack/merger.rb
simple-httpd-0.4.0 lib/simple/httpd/rack/merger.rb
simple-httpd-0.3.5 lib/simple/httpd/rack/merger.rb
simple-httpd-0.3.4 lib/simple/httpd/rack/merger.rb
simple-httpd-0.3.3 lib/simple/httpd/rack/merger.rb
simple-httpd-0.3.1 lib/simple/httpd/rack/merger.rb
simple-httpd-0.3.0 lib/simple/httpd/rack/merger.rb