Object
Does the majority of the IO processing. It has been written in Ruby using about 8 different IO processing strategies.
It is currently carefully constructed to make sure that it gets the best possible performance for the common case: GET requests that are fully complete after a single read(2)
Anyone who thinks they can make it faster is more than welcome to take a crack at it.
returns an environment hash suitable for Rack if successful This does minimal exception trapping and it is up to the caller to handle any socket errors (e.g. user aborted upload).
# File lib/unicorn/http_request.rb, line 44
44: def read(socket)
45: REQ.clear
46: PARSER.reset
47:
48: # From http://www.ietf.org/rfc/rfc3875:
49: # "Script authors should be aware that the REMOTE_ADDR and
50: # REMOTE_HOST meta-variables (see sections 4.1.8 and 4.1.9)
51: # may not identify the ultimate source of the request. They
52: # identify the client for the immediate request to the server;
53: # that client may be a proxy, gateway, or other intermediary
54: # acting on behalf of the actual source client."
55: REQ[Const::REMOTE_ADDR] =
56: TCPSocket === socket ? socket.peeraddr.last : LOCALHOST
57:
58: # short circuit the common case with small GET requests first
59: if PARSER.headers(REQ, socket.readpartial(Const::CHUNK_SIZE, BUF)).nil?
60: # Parser is not done, queue up more data to read and continue parsing
61: # an Exception thrown from the PARSER will throw us out of the loop
62: begin
63: BUF << socket.readpartial(Const::CHUNK_SIZE)
64: end while PARSER.headers(REQ, BUF).nil?
65: end
66: REQ[Const::RACK_INPUT] = 0 == PARSER.content_length ?
67: NULL_IO : Unicorn::TeeInput.new(socket, REQ, PARSER, BUF)
68: REQ.update(DEFAULTS)
69: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.