Class: PacketGen::Header::HTTP::Request
- Defined in:
- lib/packetgen/header/http/request.rb
Overview
Instance Attribute Summary collapse
-
#body ⇒ BinStruct::String
HTTP request body, if any.
-
#headers ⇒ HTTP::Headers
associated http/1.1 headers.
-
#path ⇒ BinStruct::String
Requested path.
-
#verb ⇒ BinStruct::String
HTTP verb (method).
-
#version ⇒ BinStruct::String
HTTP version.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Request
constructor
A new instance of Request.
-
#parse? ⇒ Boolean
May be parsed as a HTTP request if verb is known, and if version is
HTTP/1.x
. -
#read(str) ⇒ self
Read in the HTTP portion of the packet, and parse it.
-
#to_s ⇒ String
String representation of data.
Methods inherited from Base
bind, calculate_and_set_length, #header_id, inherited, #ip_header, #ll_header
Methods included from PacketGen::Headerable
#added_to_packet, included, #method_name, #packet, #packet=, #protocol_name
Constructor Details
#initialize(options = {}) ⇒ Request
Returns a new instance of Request.
70 71 72 73 |
# File 'lib/packetgen/header/http/request.rb', line 70 def initialize(={}) super self.headers ||= [:headers] end |
Instance Attribute Details
#body ⇒ BinStruct::String
HTTP request body, if any
63 |
# File 'lib/packetgen/header/http/request.rb', line 63 define_attr :body, BinStruct::String |
#headers ⇒ HTTP::Headers
associated http/1.1 headers
59 |
# File 'lib/packetgen/header/http/request.rb', line 59 define_attr :headers, HTTP::Headers |
#path ⇒ BinStruct::String
Requested path
51 |
# File 'lib/packetgen/header/http/request.rb', line 51 define_attr :path, BinStruct::String |
#verb ⇒ BinStruct::String
HTTP verb (method)
47 |
# File 'lib/packetgen/header/http/request.rb', line 47 define_attr :verb, BinStruct::String |
#version ⇒ BinStruct::String
HTTP version
55 |
# File 'lib/packetgen/header/http/request.rb', line 55 define_attr :version, BinStruct::String, default: 'HTTP/1.1' |
Instance Method Details
#parse? ⇒ Boolean
May be parsed as a HTTP request if verb is known, and if version is HTTP/1.x
.
94 95 96 |
# File 'lib/packetgen/header/http/request.rb', line 94 def parse? VERBS.include?(self.verb) && self.version.start_with?('HTTP/1.') end |
#read(str) ⇒ self
Read in the HTTP portion of the packet, and parse it.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/packetgen/header/http/request.rb', line 77 def read(str) lines = lines(str) first_line_words = lines.shift.split self[:verb].read(first_line_words[0]) self[:path].read(first_line_words[1]) self[:version].read(first_line_words[2]) # requests can sometimes have a payload headers, data = headers_and_payload_from_lines(lines) self[:headers].read(headers) self[:body].read(data) self end |
#to_s ⇒ String
String representation of data.
100 101 102 103 104 105 106 |
# File 'lib/packetgen/header/http/request.rb', line 100 def to_s raise FormatError, 'Missing #verb.' if self.verb.empty? raise FormatError, 'Missing #path.' if self.path.empty? raise FormatError, 'Missing #version.' if self.version.empty? "#{self.verb.dup} #{self.path} #{self.version}\r\n#{self[:headers]}#{self.body}" end |