[basic GET works von@fugal.net**20071120065347] { hunk ./webserver.rb 14 - DEFAULT_PORT=80 + DEFAULT_PORT = 80 hunk ./webserver.rb 16 - attr_accessor :serv_root + def serv_root + @serv_root || Pathname.new(ENV["HOME"]) + "public_html" + end + def serv_root= p + @serv_root = Pathname.new p + end hunk ./webserver.rb 39 - puts "got connection" hunk ./webserver.rb 45 - puts "connection..." hunk ./webserver.rb 50 - not_found.send con + serv_resource(req.resource).send con hunk ./webserver.rb 52 - puts "closed" hunk ./webserver.rb 53 - puts "thread died" hunk ./webserver.rb 55 - def not_found - r = Response.new :status => 404, :message => "Not found!" - r.content_type = "text/html" - f = Pathname.new "404.html" - if f.exist? - r << File.read("404.html") - else + def mimetype f + `file -bi #{f.to_s}`.chomp + end + def mime_icon type + type = type[/^[-\/\w]*/] + "/icons/" + type.sub("/", "-") + ".png" + end + def serv_resource resource + resource = Pathname.new resource + file = self.serv_root + resource.sub(/^./, "") + r = Response.new + r << DEFAULT_HEADERS + if file.file? # check if file exists + r.content_type = `file -bi #{file.to_s}`.chomp + r << file.read + elsif file.directory? # if it's a directory + r.content_type = "text/html" hunk ./webserver.rb 73 -Not found

404: Not found

-poop + + + #{file.basename} + + + +

Directory listing:

+

#{file.basename}

+