Class: Toto::Server
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
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.
343 344 345 |
# File 'lib/toto.rb', line 343 def config @config end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
343 344 345 |
# File 'lib/toto.rb', line 343 def site @site end |
Instance Method Details
#call(env) ⇒ Object
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/toto.rb', line 351 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 = @site.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 |