-
-
Save dubiouscript/19192c2f86dc2404bc92656dc449956c to your computer and use it in GitHub Desktop.
Revisions
-
jimfoltz revised this gist
May 13, 2018 . 1 changed file with 17 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,12 @@ require 'webrick' require 'fileutils' if ARGV.length != 0 root = ARGV.first.gsub('\\', '/') else root = '.' end BACKUP_DIR = 'bak' module WEBrick module HTTPServlet @@ -10,9 +18,11 @@ class FileHandler class DefaultFileHandler def do_PUT(req, res) file = "#{@config[:DocumentRoot]}#{req.path}" res.body = '' unless Dir.exists? BACKUP_DIR Dir.mkdir BACKUP_DIR end FileUtils.cp(file, "#{BACKUP_DIR}/#{File.basename(file, '.html')}.#{Time.now.to_i.to_s}.html") File.open(file, "w+") {|f| f.puts(req.body)} end @@ -26,11 +36,11 @@ def do_OPTIONS(req, res) end end server = WEBrick::HTTPServer.new({:Port => 8000, :DocumentRoot => root}) trap "INT" do puts "Shutting down..." server.shutdown end server.start -
jimfoltz created this gist
May 12, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ require 'webrick' module WEBrick module HTTPServlet class FileHandler alias do_PUT do_GET end class DefaultFileHandler def do_PUT(req, res) file = "#{@config[:DocumentRoot]}#{req.path}" #req.body {|buf| c << buf} res.body = '' #File.open(file, "w+") {|f| f.puts(c)} File.open(file, "w+") {|f| f.puts(req.body)} end def do_OPTIONS(req, res) res['allow'] = "GET,HEAD,POST,OPTIONS,CONNECT,PUT,DAV,dav" res['x-api-access-type'] = 'file' res['dav'] = 'tw5/put' end end end end #sRoot = "#{Dir.pwd}/html" sRoot = "#{Dir.pwd}" server = WEBrick::HTTPServer.new({:Port => 8000, :DocumentRoot => sRoot}) trap "INT" do server.shutdown end server.start