Class: SWS::Adaptor::FastCGI
Overview
FastCGI adaptor. Note that at the moment it will only run properly if you start only one instace of the application. It SHOULD work ok if you run multiple instances and use session affinity patch for mod_fastcgi, but I didn’t test that.
Constant Summary
Constants inherited from Generic
Instance Attribute Summary
Attributes inherited from Generic
Instance Method Summary collapse
-
#create_request(fcgi_request) ⇒ Object
Creates SWS::Request object using FastCGI request object.
-
#each_request ⇒ Object
Main adaptor method - invokes block for each received request.
-
#initialize ⇒ FastCGI
constructor
A new instance of FastCGI.
-
#run ⇒ Object
Run for FastCGI adaptor is in fact performed in each_request, so this method is empty.
Constructor Details
#initialize ⇒ FastCGI
Returns a new instance of FastCGI.
138 139 140 141 142 143 144 145 |
# File 'lib/sws/adaptor.rb', line 138 def initialize #The 'require' clause has been placed within initialize to avoid #exception if the FastCGI adaptor is not used and fcgi.rb is missing require 'fcgi' #Base_path will be initialized on first request, because it is not known before end |
Instance Method Details
#create_request(fcgi_request) ⇒ Object
Creates SWS::Request object using FastCGI request object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/sws/adaptor.rb', line 177 def create_request ( fcgi_request ) request_method = fcgi_request.env["REQUEST_METHOD"] path = fcgi_request.env["PATH_INFO"] || "/" # This may be invalid - but it isn't propably important http_version = fcgi_request.env["SERVER_PROTOCOL"] query_string = fcgi_request.env["QUERY_STRING"] # We wan't the same behaviour as Standalone adaptor has if query_string == "" then query_string = nil end request = Request.new( request_method, path, query_string, http_version ) HEADER_TRANSLATION.each do |original_header,request_header| request.headers[request_header] = fcgi_request.env[original_header] end content_length = fcgi_request.env["CONTENT_LENGTH"] if ( content_length ) request.content = fcgi_request.in.read( content_length.to_i ) end fcgi_request.env.each do |key,value| unless HEADER_TRANSLATION.has_key?( key ) request.headers[key.downcase] = value end end request.process_headers() request.process_content() if ( request.has_content? ) return request end |
#each_request ⇒ Object
Main adaptor method - invokes block for each received request
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/sws/adaptor.rb', line 156 def each_request () FCGI.each_request do |fcgi_request| #This is a FCGI request, not a SWS one - we need to transform it sws_request = create_request( fcgi_request ) # Base path can only be deducted after first request unless ( @base_path ) @base_path = fcgi_request.env["SCRIPT_NAME"] + "/" end response = yield( sws_request ) fcgi_request.out.print( "Status: #{response.status}\r\n" ) fcgi_request.out.print( response.to_s ) fcgi_request.finish end end |
#run ⇒ Object
Run for FastCGI adaptor is in fact performed in each_request, so this method is empty
150 151 152 |
# File 'lib/sws/adaptor.rb', line 150 def run end |