Class: Arachni::HTTP::Headers
Overview
HTTP Headers.
For convenience, Hash-like getters and setters provide case-insensitive access.
Constant Summary collapse
- FORMATTED_NAMES_CACHE =
Support::Cache::LeastRecentlyPushed.new( 100 )
- CONTENT_TYPE =
'content-type'
- SET_COOKIE =
'set-cookie'
- LOCATION =
'location'
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, #recode!, #stringify_recursively_and_freeze
Constructor Details
#initialize(headers = {}) ⇒ Headers
Returns a new instance of Headers.
28 29 30 |
# File 'lib/arachni/http/headers.rb', line 28 def initialize( headers = {} ) merge!( headers || {} ) end |
Instance Method Details
#[](field) ⇒ String
‘field` will be capitalized appropriately before storing.
Returns Field value.
74 75 76 |
# File 'lib/arachni/http/headers.rb', line 74 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`.
87 88 89 90 |
# File 'lib/arachni/http/headers.rb', line 87 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.
94 95 96 |
# File 'lib/arachni/http/headers.rb', line 94 def content_type self[CONTENT_TYPE] end |
#cookies ⇒ Array<Hash>
Returns Cookies as hashes.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/arachni/http/headers.rb', line 113 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.
52 53 54 |
# File 'lib/arachni/http/headers.rb', line 52 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.
63 64 65 |
# File 'lib/arachni/http/headers.rb', line 63 def include?( field ) super format_field_name( field.to_s.downcase ) end |
#location ⇒ String?
Returns Value of the ‘Location` field.
100 101 102 |
# File 'lib/arachni/http/headers.rb', line 100 def location self[LOCATION] end |
#merge!(headers) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/arachni/http/headers.rb', line 32 def merge!( headers ) headers.each do |k, v| # Handle headers with identical normalized names, like a mixture of # Set-Cookie and SET-COOKIE. if include? k self[k] = [self[k]].flatten self[k] << v else self[k] = v end end end |
#set_cookie ⇒ Array<String>
Returns Set-cookie strings.
106 107 108 109 |
# File 'lib/arachni/http/headers.rb', line 106 def return [] if self[SET_COOKIE].to_s.empty? [self[SET_COOKIE]].flatten end |