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 45
45: def initialize
46: @parser = HttpParser.new
47: @data = ''
48: @nparsed = 0
49: @body = StringIO.new
50: @env = {
51: SERVER_SOFTWARE => SERVER,
52:
53: # Rack stuff
54: RACK_INPUT => @body,
55:
56: RACK_VERSION => VERSION::RACK,
57: RACK_ERRORS => STDERR,
58:
59: RACK_MULTITHREAD => false,
60: RACK_MULTIPROCESS => false,
61: RACK_RUN_ONCE => false
62: }
63: end
Public Instance close()
Close any resource used by the request
[ show source ]
# File lib/thin/request.rb, line 130
130: def close
131: @body.delete if @body.class == Tempfile
132: end
Public Instance content_length()
Expected size of the body
[ show source ]
# File lib/thin/request.rb, line 97
97: def content_length
98: @env[CONTENT_LENGTH].to_i
99: end
Public Instance finished?()
true if headers and body are finished parsing
[ show source ]
# File lib/thin/request.rb, line 92
92: def finished?
93: @parser.finished? && @body.size >= content_length
94: end
Public Instance forwarded_for()
[ show source ]
# File lib/thin/request.rb, line 121
121: def forwarded_for
122: @env[FORWARDED_FOR]
123: 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 68
68: def parse(data)
69: if @parser.finished? # Header finished, can only be some more body
70: body << data
71: else # Parse more header using the super parser
72: @data << data
73: raise InvalidRequest, 'Header longer than allowed' if @data.size > MAX_HEADER
74:
75: @nparsed = @parser.execute(@env, @data, @nparsed)
76:
77: # Transfert to a tempfile if body is very big
78: move_body_to_tempfile if @parser.finished? && content_length > MAX_BODY
79: end
80:
81:
82: if finished? # Check if header and body are complete
83: @data = nil
84: @body.rewind
85: true # Request is fully parsed
86: else
87: false # Not finished, need more data
88: end
89: end
Public Instance persistent?()
Returns true if the client expect the connection to be persistent.
[ show source ]
# File lib/thin/request.rb, line 102
102: def persistent?
103: # Clients and servers SHOULD NOT assume that a persistent connection
104: # is maintained for HTTP versions less than 1.1 unless it is explicitly
105: # signaled. (http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html)
106: if @env[HTTP_VERSION] == HTTP_1_0
107: @env[CONNECTION] =~ KEEP_ALIVE_REGEXP
108:
109: # HTTP/1.1 client intends to maintain a persistent connection unless
110: # a Connection header including the connection-token "close" was sent
111: # in the request
112: else
113: @env[CONNECTION].nil? || @env[CONNECTION] !~ CLOSE_REGEXP
114: end
115: end
Public Instance remote_address=(address)
[ show source ]
# File lib/thin/request.rb, line 117
117: def remote_address=(address)
118: @env[REMOTE_ADDR] = address
119: end
Public Instance threaded=(value)
[ show source ]
# File lib/thin/request.rb, line 125
125: def threaded=(value)
126: @env[RACK_MULTITHREAD] = value
127: end