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.
249 250 251 |
# File 'lib/toto.rb', line 249 def config @config end |
Instance Method Details
#call(env) ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/toto.rb', line 256 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 @response['Content-Type'] = Rack::Mime.mime_type(".#{response[:type]}") # Cache for one day @response['Cache-Control'] = "public, max-age=86400" @response['Etag'] = Digest::SHA1.hexdigest(response[:body]) @response.status = response[:status] @response.finish end |