Class: Ronin::App::Validations::HTTPParams

Inherits:
Dry::Validation::Contract
  • Object
show all
Defined in:
lib/ronin/app/validations/http_params.rb

Overview

Validations for the form params submitted to POST /network/http.

Constant Summary collapse

HTTPMethods =
Types::Symbol.enum(
  copy:      'COPY',
  delete:    'DELETE',
  get:       'GET',
  head:      'HEAD',
  lock:      'LOCK',
  mkcol:     'MKCOL',
  move:      'MOVE',
  options:   'OPTIONS',
  patch:     'PATCH',
  post:      'POST',
  propfind:  'PROPFIND',
  proppatch: 'PROPPATCH',
  put:       'PUT',
  trace:     'TRACE',
  unlock:    'UNLOCK'
)
Versions =
(Types::Float | Types::Integer).enum(
  1   => '1.0',
  1.1 => '1.1',
  1.2 => '1.2'
)
VerificationModes =
Types::Symbol.enum(
  none:                 'none',
  peer:                 'peer',
  fail_if_no_peer_cert: 'fail_if_no_peer_cert'
)
Headers =
Types::Hash.constructor do |input,type|
  if input.is_a?(String)
    headers = {}

    input.strip.each_line(chomp: true) do |line|
      name, value = line.split(/:\s*/,2)

      case (previous_value = headers[name])
      when nil # no value yet
        headers[name] = value
      when String # previous value
        headers[name] = [previous_value, value]
      when Array # multiple previous values
        previous_value << value
      end
    end

    headers unless headers.empty?
  elsif type.valid?(input)
    input
  else
    type.call(input)
  end
end

Class Method Summary collapse

Class Method Details

.call(params) ⇒ Dry::Validation::Result

Initializes and calls the validation contract.

Parameters:

  • params (Hash{String => Object})

    The HTTP params to validate.

Returns:

  • (Dry::Validation::Result)

    The validation result.



119
120
121
# File 'lib/ronin/app/validations/http_params.rb', line 119

def self.call(params)
  new.call(params)
end