Object
A request sent by the client to the server.
Maximum request body size before it is moved out of memory and into a tempfile for reading.
Freeze some HTTP header names & values
Freeze some Rack header names
# File lib/thin/request.rb, line 51
51: def initialize
52: @parser = Thin::HttpParser.new
53: @data = ''
54: @nparsed = 0
55: @body = StringIO.new(INITIAL_BODY.dup)
56: @env = {
57: SERVER_SOFTWARE => SERVER,
58: SERVER_NAME => LOCALHOST,
59:
60: # Rack stuff
61: RACK_INPUT => @body,
62:
63: RACK_VERSION => VERSION::RACK,
64: RACK_ERRORS => STDERR,
65:
66: RACK_MULTITHREAD => false,
67: RACK_MULTIPROCESS => false,
68: RACK_RUN_ONCE => false
69: }
70: end
# File lib/thin/request.rb, line 132
132: def async_callback=(callback)
133: @env[ASYNC_CALLBACK] = callback
134: @env[ASYNC_CLOSE] = EventMachine::DefaultDeferrable.new
135: end
# File lib/thin/request.rb, line 137
137: def async_close
138: @async_close ||= @env[ASYNC_CLOSE]
139: end
Close any resource used by the request
# File lib/thin/request.rb, line 142
142: def close
143: @body.delete if @body.class == Tempfile
144: end
Expected size of the body
# File lib/thin/request.rb, line 104
104: def content_length
105: @env[CONTENT_LENGTH].to_i
106: end
true if headers and body are finished parsing
# File lib/thin/request.rb, line 99
99: def finished?
100: @parser.finished? && @body.size >= content_length
101: end
Parse a chunk of data into the request environment Raises a InvalidRequest if invalid. Returns true if the parsing is complete.
# File lib/thin/request.rb, line 75
75: def parse(data)
76: if @parser.finished? # Header finished, can only be some more body
77: body << data
78: else # Parse more header using the super parser
79: @data << data
80: raise InvalidRequest, 'Header longer than allowed' if @data.size > MAX_HEADER
81:
82: @nparsed = @parser.execute(@env, @data, @nparsed)
83:
84: # Transfert to a tempfile if body is very big
85: move_body_to_tempfile if @parser.finished? && content_length > MAX_BODY
86: end
87:
88:
89: if finished? # Check if header and body are complete
90: @data = nil
91: @body.rewind
92: true # Request is fully parsed
93: else
94: false # Not finished, need more data
95: end
96: end
Returns true if the client expect the connection to be persistent.
# File lib/thin/request.rb, line 109
109: def persistent?
110: # Clients and servers SHOULD NOT assume that a persistent connection
111: # is maintained for HTTP versions less than 1.1 unless it is explicitly
112: # signaled. (http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html)
113: if @env[HTTP_VERSION] == HTTP_1_0
114: @env[CONNECTION] =~ KEEP_ALIVE_REGEXP
115:
116: # HTTP/1.1 client intends to maintain a persistent connection unless
117: # a Connection header including the connection-token "close" was sent
118: # in the request
119: else
120: @env[CONNECTION].nil? || @env[CONNECTION] !~ CLOSE_REGEXP
121: end
122: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.