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.
-
#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 = {} ) (headers || {}).each { |k, v| self[k] = v } end |
Instance Method Details
#[](field) ⇒ String
‘field` will be capitalized appropriately before storing.
Returns Field value.
55 56 57 |
# File 'lib/arachni/http/headers.rb', line 55 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`.
68 69 70 71 |
# File 'lib/arachni/http/headers.rb', line 68 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.
75 76 77 |
# File 'lib/arachni/http/headers.rb', line 75 def content_type self['content-type'] end |
#cookies ⇒ Array<Hash>
Returns Cookies as hashes.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/arachni/http/headers.rb', line 94 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.
33 34 35 |
# File 'lib/arachni/http/headers.rb', line 33 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.
44 45 46 |
# File 'lib/arachni/http/headers.rb', line 44 def include?( field ) super format_field_name( field.to_s.downcase ) end |
#location ⇒ String?
Returns Value of the ‘Location` field.
81 82 83 |
# File 'lib/arachni/http/headers.rb', line 81 def location self['location'] end |