Class: Toto::Server
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(config = {}, &blk) ⇒ Server
constructor
A new instance of Server.
Constructor Details
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
310 311 312 |
# File 'lib/toto-haml.rb', line 310 def config @config end |
Instance Method Details
#call(env) ⇒ Object
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/toto-haml.rb', line 317 def call env @request = Rack::Request.new env @response = Rack::Response.new return [400, {}, []] unless @request.get? path, mime = @request.path_info.split('.') route = (path || '/').split('/').reject {|i| i.empty? } response = Toto::Site.new(@config).go(route, *(mime ? mime : [])) @response.body = [response[:body]] @response['Content-Length'] = response[:body].length.to_s unless response[:body].empty? @response['Content-Type'] = Rack::Mime.mime_type(".#{response[:type]}") # Set http cache headers @response['Cache-Control'] = if Toto.env == 'production' "public, max-age=#{@config[:cache]}" else "no-cache, must-revalidate" end @response['Etag'] = Digest::SHA1.hexdigest(response[:body]) @response.status = response[:status] @response.finish end |