Class: Thin::Request
Class Thin::Request < Object
(in files lib/thin/request.rb )A request sent by the client to the server.
Includes
Methods
Public Class new()
[ show source ]
# File lib/thin/request.rb, line 49
49: def initialize
50: @parser = Thin::HttpParser.new
51: @data = ''
52: @nparsed = 0
53: @body = StringIO.new
54: @env = {
55: SERVER_SOFTWARE => SERVER,
56: SERVER_NAME => LOCALHOST,
57:
58: # Rack stuff
59: RACK_INPUT => @body,
60:
61: RACK_VERSION => VERSION::RACK,
62: RACK_ERRORS => STDERR,
63:
64: RACK_MULTITHREAD => false,
65: RACK_MULTIPROCESS => false,
66: RACK_RUN_ONCE => false
67: }
68: end
Public Instance async_callback=(callback)
[ show source ]
# File lib/thin/request.rb, line 134
134: def async_callback=(callback)
135: @env[ASYNC_CALLBACK] = callback
136: @env[ASYNC_CLOSE] = EventMachine::DefaultDeferrable.new
137: end
Public Instance async_close()
[ show source ]
# File lib/thin/request.rb, line 139
139: def async_close
140: @async_close ||= @env[ASYNC_CLOSE]
141: end
Public Instance close()
Close any resource used by the request
[ show source ]
# File lib/thin/request.rb, line 144
144: def close
145: @body.delete if @body.class == Tempfile
146: end
Public Instance content_length()
Expected size of the body
[ show source ]
# File lib/thin/request.rb, line 102
102: def content_length
103: @env[CONTENT_LENGTH].to_i
104: end
Public Instance finished?()
true if headers and body are finished parsing
[ show source ]
# File lib/thin/request.rb, line 97
97: def finished?
98: @parser.finished? && @body.size >= content_length
99: end
Public Instance forwarded_for()
[ show source ]
# File lib/thin/request.rb, line 126
126: def forwarded_for
127: @env[FORWARDED_FOR]
128: end
Public Instance parse(data)
Parse a chunk of data into the request environment Raises a InvalidRequest if invalid. Returns true if the parsing is complete.
[ show source ]
# File lib/thin/request.rb, line 73
73: def parse(data)
74: if @parser.finished? # Header finished, can only be some more body
75: body << data
76: else # Parse more header using the super parser
77: @data << data
78: raise InvalidRequest, 'Header longer than allowed' if @data.size > MAX_HEADER
79:
80: @nparsed = @parser.execute(@env, @data, @nparsed)
81:
82: # Transfert to a tempfile if body is very big
83: move_body_to_tempfile if @parser.finished? && content_length > MAX_BODY
84: end
85:
86:
87: if finished? # Check if header and body are complete
88: @data = nil
89: @body.rewind
90: true # Request is fully parsed
91: else
92: false # Not finished, need more data
93: end
94: end
Public Instance persistent?()
Returns true if the client expect the connection to be persistent.
[ show source ]
# File lib/thin/request.rb, line 107
107: def persistent?
108: # Clients and servers SHOULD NOT assume that a persistent connection
109: # is maintained for HTTP versions less than 1.1 unless it is explicitly
110: # signaled. (http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html)
111: if @env[HTTP_VERSION] == HTTP_1_0
112: @env[CONNECTION] =~ KEEP_ALIVE_REGEXP
113:
114: # HTTP/1.1 client intends to maintain a persistent connection unless
115: # a Connection header including the connection-token "close" was sent
116: # in the request
117: else
118: @env[CONNECTION].nil? || @env[CONNECTION] !~ CLOSE_REGEXP
119: end
120: end
Public Instance remote_address=(address)
[ show source ]
# File lib/thin/request.rb, line 122
122: def remote_address=(address)
123: @env[REMOTE_ADDR] = address
124: end
Public Instance threaded=(value)
[ show source ]
# File lib/thin/request.rb, line 130
130: def threaded=(value)
131: @env[RACK_MULTITHREAD] = value
132: end