123456789_123456789_123456789_123456789_123456789_

Class: Rack::Lint

Relationships & Source Files
Namespace Children
Classes:
Exceptions:
Inherits: Object
Defined in: lib/rack/lint.rb

Overview

Validates your application and the requests and responses according to the ::Rack spec. See SPEC.rdoc for details.

Constant Summary

  • ALLOWED_SCHEMES = Internal use only
    # File 'lib/rack/lint.rb', line 21
    %w(https http wss ws).freeze
  • HOST_PATTERN = private Internal use only

    Match a host name, according to RFC3986. Copied from URI::RFC3986_Parser::HOST because older Ruby versions (< 3.3) don’t expose it.

    # File 'lib/rack/lint.rb', line 29
    /
      (?<IP-literal>\[(?:
          (?<IPv6address>
            (?:\h{1,4}:){6}
            (?<ls32>\h{1,4}:\h{1,4}
            | (?<IPv4address>(?<dec-octet>[1-9]\d|1\d{2}|2[0-4]\d|25[0-5]|\d)
                \.\g<dec-octet>\.\g<dec-octet>\.\g<dec-octet>)
            )
          | ::(?:\h{1,4}:){5}\g<ls32>
          | \h{1,4}?::(?:\h{1,4}:){4}\g<ls32>
          | (?:(?:\h{1,4}:)?\h{1,4})?::(?:\h{1,4}:){3}\g<ls32>
          | (?:(?:\h{1,4}:){,2}\h{1,4})?::(?:\h{1,4}:){2}\g<ls32>
          | (?:(?:\h{1,4}:){,3}\h{1,4})?::\h{1,4}:\g<ls32>
          | (?:(?:\h{1,4}:){,4}\h{1,4})?::\g<ls32>
          | (?:(?:\h{1,4}:){,5}\h{1,4})?::\h{1,4}
          | (?:(?:\h{1,4}:){,6}\h{1,4})?::
          )
        | (?<IPvFuture>v\h\.[!$&-.0-9:;=A-Z_a-z~])
        )\])
    | \g<IPv4address>
    | (?<reg-name>(?:%\h\h|[!$&-.0-9;=A-Z_a-z~])*+)
    /x.freeze
  • HTTP_HOST_PATTERN = private Internal use only
    # File 'lib/rack/lint.rb', line 52
    /\A#{HOST_PATTERN}(:\d*+)?\z/.freeze
  • REQUEST_PATH_ABSOLUTE_FORM = Internal use only
    # File 'lib/rack/lint.rb', line 24
    /\A#{Utils::URI_PARSER.make_regexp}\z/
  • REQUEST_PATH_ASTERISK_FORM = Internal use only
    # File 'lib/rack/lint.rb', line 26
    '*'
  • REQUEST_PATH_AUTHORITY_FORM = Internal use only
    # File 'lib/rack/lint.rb', line 25
    /\A[^\/:]:\d\z/
  • REQUEST_PATH_ORIGIN_FORM = Internal use only
    # File 'lib/rack/lint.rb', line 23
    /\A\/[^#]*\z/
  • SERVER_NAME_PATTERN = private Internal use only
    # File 'lib/rack/lint.rb', line 51
    /\A#{HOST_PATTERN}\z/.freeze

Class Method Summary

Instance Method Summary

Constructor Details

.new(app) ⇒ Lint

This method is for internal use only.

N.B. The empty ## comments creates paragraphs in the output. A trailing “" is used to escape the newline character, which combines the comments into a single paragraph.

Rack Specification

This specification aims to formalize the ::Rack protocol. You can (and should) use Lint to enforce it. When you develop middleware, be sure to test with Lint to catch possible violations of this specification.

The Application

A Rack application is a Ruby object that responds to #call. \

Raises:

[ GitHub ]

  
# File 'lib/rack/lint.rb', line 65

def initialize(app)
  raise LintError, "app must respond to call" unless app.respond_to?(:call)

  @app = app
end

Instance Method Details

#call(env = nil)

Invoke the application, validating the request and response according to the ::Rack spec.

[ GitHub ]

  
# File 'lib/rack/lint.rb', line 15

def call(env = nil)
  Wrapper.new(@app, env).response
end