Class: Mongrel2Request

Inherits:
Object
  • Object
show all
Defined in:
lib/dripdrop/handlers/mongrel2.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sender, conn_id, path, headers, body) ⇒ Mongrel2Request

Returns a new instance of Mongrel2Request.



133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/dripdrop/handlers/mongrel2.rb', line 133

def initialize(sender, conn_id, path, headers, body)
  @sender  = sender
  @conn_id = conn_id
  @path    = path
  @headers = headers
  @body    = body

  if headers['METHOD'] == 'JSON'
    @data = JSON.parse(@body)
  else
    @data = {}
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



131
132
133
# File 'lib/dripdrop/handlers/mongrel2.rb', line 131

def body
  @body
end

#conn_idObject (readonly)

Returns the value of attribute conn_id.



131
132
133
# File 'lib/dripdrop/handlers/mongrel2.rb', line 131

def conn_id
  @conn_id
end

#headersObject (readonly)

Returns the value of attribute headers.



131
132
133
# File 'lib/dripdrop/handlers/mongrel2.rb', line 131

def headers
  @headers
end

#pathObject (readonly)

Returns the value of attribute path.



131
132
133
# File 'lib/dripdrop/handlers/mongrel2.rb', line 131

def path
  @path
end

#senderObject (readonly)

Returns the value of attribute sender.



131
132
133
# File 'lib/dripdrop/handlers/mongrel2.rb', line 131

def sender
  @sender
end

Class Method Details

.parse_netstring(ns) ⇒ Object



147
148
149
150
151
152
# File 'lib/dripdrop/handlers/mongrel2.rb', line 147

def self.parse_netstring(ns)
  len, rest = ns.split(':', 2)
  len = len.to_i
  raise "Netstring did not end in ','" unless rest[len].chr == ','
  [rest[0...len], rest[(len+1)..-1]]
end

.parse_request(msg) ⇒ Object



154
155
156
157
158
159
160
161
162
# File 'lib/dripdrop/handlers/mongrel2.rb', line 154

def self.parse_request(msg)
  sender, conn_id, path, rest = msg.copy_out_string.split(' ', 4)
  headers, head_rest = parse_netstring(rest)
  body, _ = parse_netstring(head_rest)

  headers = JSON.parse(headers)

  self.new(sender, conn_id, path, headers, body)
end