Class: Arachni::HTTP::Headers
Overview
HTTP Headers.
For convenience, Hash-like getters and setters provide case-insensitive access.
Instance Method Summary collapse
-
#[](field) ⇒ String
Field value.
-
#[]=(field, value) ⇒ String
Field ‘value`.
-
#content_type ⇒ String?
Value of the ‘Content-Type` field.
-
#cookies ⇒ Array<Hash>
Cookies as hashes.
-
#delete(field) ⇒ String
Field value.
-
#include?(field) ⇒ String
Field value.
-
#initialize(headers = {}) ⇒ Headers
constructor
A new instance of Headers.
-
#location ⇒ String?
Value of the ‘Location` field.
- #merge!(headers) ⇒ Object
-
#set_cookie ⇒ Array<String>
Set-cookie strings.
Methods inherited from Hash
#apply_recursively, #downcase, #find_symbol_keys_recursively, #my_stringify, #my_stringify_keys, #my_symbolize_keys, #recode, #stringify_recursively_and_freeze
Constructor Details
#initialize(headers = {}) ⇒ Headers
Returns a new instance of Headers.
22 23 24 |
# File 'lib/arachni/http/headers.rb', line 22 def initialize( headers = {} ) merge!( headers || {} ) end |
Instance Method Details
#[](field) ⇒ String
‘field` will be capitalized appropriately before storing.
Returns Field value.
59 60 61 |
# File 'lib/arachni/http/headers.rb', line 59 def []( field ) super format_field_name( field.to_s.downcase ).freeze end |
#[]=(field, value) ⇒ String
‘field` will be capitalized appropriately before storing.
Returns Field ‘value`.
72 73 74 75 |
# File 'lib/arachni/http/headers.rb', line 72 def []=( field, value ) super format_field_name( field.to_s.downcase ).freeze, value.is_a?( Array ) ? value : value.to_s.freeze end |
#content_type ⇒ String?
Returns Value of the ‘Content-Type` field.
79 80 81 |
# File 'lib/arachni/http/headers.rb', line 79 def content_type self['content-type'] end |
#cookies ⇒ Array<Hash>
Returns Cookies as hashes.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/arachni/http/headers.rb', line 98 def return [] if .empty? .map do || WEBrick::Cookie.( ).flatten.uniq.map do || = {} .instance_variables.each do |var| [var.to_s.gsub( /@/, '' ).to_sym] = .instance_variable_get( var ) end # Replace the string with a Time object. [:expires] = .expires end end.flatten.compact end |
#delete(field) ⇒ String
‘field` will be capitalized appropriately before storing.
Returns Field value.
37 38 39 |
# File 'lib/arachni/http/headers.rb', line 37 def delete( field ) super format_field_name( field.to_s.downcase ) end |
#include?(field) ⇒ String
‘field` will be capitalized appropriately before storing.
Returns Field value.
48 49 50 |
# File 'lib/arachni/http/headers.rb', line 48 def include?( field ) super format_field_name( field.to_s.downcase ) end |
#location ⇒ String?
Returns Value of the ‘Location` field.
85 86 87 |
# File 'lib/arachni/http/headers.rb', line 85 def location self['location'] end |
#merge!(headers) ⇒ Object
26 27 28 |
# File 'lib/arachni/http/headers.rb', line 26 def merge!( headers ) headers.each { |k, v| self[k] = v } end |