Parent

Thin::Request

A request sent by the client to the server.

Constants

MAX_BODY

Maximum request body size before it is moved out of memory and into a tempfile for reading.

BODY_TMPFILE
MAX_HEADER
INITIAL_BODY
SERVER_SOFTWARE

Freeze some HTTP header names & values

SERVER_NAME
LOCALHOST
HTTP_VERSION
HTTP_1_0
REMOTE_ADDR
CONTENT_LENGTH
CONNECTION
KEEP_ALIVE_REGEXP
CLOSE_REGEXP
RACK_INPUT

Freeze some Rack header names

RACK_VERSION
RACK_ERRORS
RACK_MULTITHREAD
RACK_MULTIPROCESS
RACK_RUN_ONCE
ASYNC_CALLBACK
ASYNC_CLOSE

Attributes

env[R]

CGI-like request environment variables

data[R]

Unparsed data of the request

body[R]

Request body

Public Class Methods

new() click to toggle source
    # 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

Public Instance Methods

async_callback=(callback) click to toggle source
     # 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
async_close() click to toggle source
     # File lib/thin/request.rb, line 137
137:     def async_close
138:       @async_close ||= @env[ASYNC_CLOSE]
139:     end
close() click to toggle source

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
content_length() click to toggle source

Expected size of the body

     # File lib/thin/request.rb, line 104
104:     def content_length
105:       @env[CONTENT_LENGTH].to_i
106:     end
finished?() click to toggle source

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(data) click to toggle source

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
persistent?() click to toggle source

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
remote_address=(address) click to toggle source
     # File lib/thin/request.rb, line 124
124:     def remote_address=(address)
125:       @env[REMOTE_ADDR] = address
126:     end
threaded=(value) click to toggle source
     # File lib/thin/request.rb, line 128
128:     def threaded=(value)
129:       @env[RACK_MULTITHREAD] = value
130:     end

Private Instance Methods

move_body_to_tempfile() click to toggle source
     # File lib/thin/request.rb, line 147
147:       def move_body_to_tempfile
148:         current_body = @body
149:         current_body.rewind
150:         @body = Tempfile.new(BODY_TMPFILE)
151:         @body.binmode
152:         @body << current_body.read
153:         @env[RACK_INPUT] = @body
154:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.