Class: Mongrel::HttpRequest
- Inherits:
-
Object
- Object
- Mongrel::HttpRequest
- 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
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(params, initial_body, socket) ⇒ HttpRequest
constructor
You don’t really call this.
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.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/mongrel.rb', line 173 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] if params[Const::HTTP_CONTENT_TYPE] params[Const::GATEWAY_INTERFACE]=Const::GATEWAY_INTERFACE_VALUE params[Const::REMOTE_ADDR]=socket.peeraddr[3] host,port = params[Const::HTTP_HOST].split(":") params[Const::SERVER_NAME]=host params[Const::SERVER_PORT]=port || 80 params[Const::SERVER_PROTOCOL]=Const::SERVER_PROTOCOL_VALUE params[Const::SERVER_SOFTWARE]=Const::MONGREL_VERSION # 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
#body ⇒ Object (readonly)
Returns the value of attribute body.
168 169 170 |
# File 'lib/mongrel.rb', line 168 def body @body end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
168 169 170 |
# File 'lib/mongrel.rb', line 168 def params @params end |