class Arachni::HTTP::Headers
For convenience, Hash-like getters and setters provide case-insensitive access.
@author Tasos Laskos <tasos.laskos@arachni-scanner.com>
Constants
- CONTENT_TYPE
- FORMATTED_NAMES_CACHE
- LOCATION
- SET_COOKIE
Public Class Methods
new( headers = {} )
click to toggle source
@param [Headers, Hash] headers
# File lib/arachni/http/headers.rb, line 28 def initialize( headers = {} ) merge!( headers || {} ) end
Private Class Methods
format_field_name( field )
click to toggle source
# File lib/arachni/http/headers.rb, line 142 def self.format_field_name( field ) # If there's a '--' somewhere in there then skip it, it probably is an # audit payload. return field if field.include?( '--' ) FORMATTED_NAMES_CACHE.fetch field do field.split( '-' ).map( &:capitalize ).join( '-' ) end end
Public Instance Methods
[]( field )
click to toggle source
@note ‘field` will be capitalized appropriately before storing.
@param [String] field
Field name
@return [String]
Field value.
Calls superclass method
# File lib/arachni/http/headers.rb, line 80 def []( field ) super format_field_name( field.to_s.downcase ).freeze end
[]=( field, value )
click to toggle source
@note ‘field` will be capitalized appropriately before storing.
@param [String] field
Field name
@param [Array<String>, String] value
Field value.
@return [String]
Field `value`.
Calls superclass method
# File lib/arachni/http/headers.rb, line 93 def []=( field, value ) super format_field_name( field.to_s.downcase ).freeze, value.is_a?( Array ) ? value : value.to_s.freeze end
content_type()
click to toggle source
@return [String, nil]
Value of the `Content-Type` field.
# File lib/arachni/http/headers.rb, line 100 def content_type (ct = self[CONTENT_TYPE]).is_a?( Array ) ? ct.first : ct end
delete( field )
click to toggle source
@note ‘field` will be capitalized appropriately before storing.
@param [String] field
Field name
@return [String]
Field value.
Calls superclass method
# File lib/arachni/http/headers.rb, line 58 def delete( field ) super format_field_name( field.to_s.downcase ) end
include?( field )
click to toggle source
@note ‘field` will be capitalized appropriately before storing.
@param [String] field
Field name
@return [String]
Field value.
Calls superclass method
# File lib/arachni/http/headers.rb, line 69 def include?( field ) super format_field_name( field.to_s.downcase ) end
location()
click to toggle source
@return [String, nil]
Value of the `Location` field.
# File lib/arachni/http/headers.rb, line 106 def location self[LOCATION] end
merge( headers, convert_to_array = true )
click to toggle source
# File lib/arachni/http/headers.rb, line 45 def merge( headers, convert_to_array = true ) d = dup d.merge! headers, convert_to_array d end
merge!( headers, convert_to_array = true )
click to toggle source
# File lib/arachni/http/headers.rb, line 32 def merge!( headers, convert_to_array = true ) headers.each do |k, v| # Handle headers with identical normalized names, like a mixture of # Set-Cookie and SET-COOKIE. if convert_to_array && include?( k ) self[k] = [self[k]].flatten self[k] << v else self[k] = v end end end
Private Instance Methods
format_field_name( field )
click to toggle source
# File lib/arachni/http/headers.rb, line 138 def format_field_name( field ) self.class.format_field_name( field ) end