Class: Mongrel::HttpRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/mongrel.rb

Overview

When a handler is found for a registered URI then this class is constructed and passed to your HttpHandler::process method. You should assume that one handler processes all requests. Included in the HttpReqeust is a HttpRequest.params Hash that matches common CGI params, and a HttpRequest.body which is a string containing the request body (raw for now).

Mongrel really only supports small-ish request bodies right now since really huge ones have to be completely read off the wire and put into a string. Later there will be several options for efficiently handling large file uploads.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, initial_body, socket) ⇒ HttpRequest

You don’t really call this. It’s made for you. Main thing it does is hook up the params, and store any remaining body data into the HttpRequest.body attribute.



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/mongrel.rb', line 142

def initialize(params, initial_body, socket)
  @body = initial_body || ""
  @params = params
  @socket = socket
  
  # fix up the CGI requirements
  params[Const::CONTENT_LENGTH] = params[Const::HTTP_CONTENT_LENGTH] || 0
  params[Const::CONTENT_TYPE] ||= params[Const::HTTP_CONTENT_TYPE]

  # now, if the initial_body isn't long enough for the content length we have to fill it
  # TODO: adapt for big ass stuff by writing to a temp file
  clen = params[Const::HTTP_CONTENT_LENGTH].to_i
  if @body.length < clen
    @body << @socket.read(clen - @body.length)
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



137
138
139
# File 'lib/mongrel.rb', line 137

def body
  @body
end

#paramsObject (readonly)

Returns the value of attribute params.



137
138
139
# File 'lib/mongrel.rb', line 137

def params
  @params
end