Sha256: 95bab45c4c06a6b49924c91b5b638e7e906d804fff2a835fcff7944f931f79e1

Contents?: true

Size: 1.81 KB

Versions: 5

Compression:

Stored size: 1.81 KB

Contents

=begin
    Copyright 2010-2014 Tasos Laskos <tasos.laskos@arachni-scanner.com>

    This file is part of the Arachni Framework project and is subject to
    redistribution and commercial restrictions. Please see the Arachni Framework
    web site for more information on licensing and terms of use.
=end

module Arachni
module HTTP

# @author Tasos Laskos <tasos.laskos@arachni-scanner.com>
class Message
    require_relative 'message/scope'

    # @return   [String]
    #   Resource location.
    attr_accessor :url

    # @return   [Headers<String, String>]
    #   HTTP headers as a Hash-like object.
    attr_accessor :headers

    # @return   [String]
    #   {Request}/{Response} body.
    attr_accessor :body

    # @note All options will be sent through the class setters whenever
    #   possible to allow for normalization.
    #
    # @param    [Hash]  options
    #   Message options.
    # @option   options [String]    :url
    #   URL.
    # @option   options [Hash]      :headers
    #   HTTP headers.
    # @option   options [String]    :body
    #   Body.
    def initialize( options = {} )
        options.each do |k, v|
            v = my_dup( v )
            begin
                send( "#{k}=", v )
            rescue NoMethodError
                instance_variable_set( "@#{k}".to_sym, v )
            end
        end

        fail ArgumentError, 'Missing :url.' if url.to_s.empty?

        @headers = Headers.new( @headers )
    end

    # @return   [Scope]
    def scope
        @scope ||= self.class::Scope.new( self )
    end

    def parsed_url
        # Don't cache this, that's already handled by the URI parser's own cache.
        Arachni::URI( url )
    end

    def url=( url )
        @url = Arachni::URI( url ).to_s.freeze
    end

    private

    def my_dup( value )
        value.dup rescue value
    end

end
end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
arachni-1.0.4 lib/arachni/http/message.rb
arachni-1.0.3 lib/arachni/http/message.rb
arachni-1.0.2 lib/arachni/http/message.rb
arachni-1.0.1 lib/arachni/http/message.rb
arachni-1.0 lib/arachni/http/message.rb