Last active
June 19, 2019 21:52
-
-
Save keyboard-slayer/037cffc25649061b6492c8b43e7f3b25 to your computer and use it in GitHub Desktop.
Reponse to the issue #1 of https://github.com/0v3rl0w/e013
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 characters
require 'socket' | |
class WebServer | |
def initialize(port, remove=false) | |
@port = port | |
@remove = remove | |
@socket = TCPServer.open(port) | |
end | |
def mainloop | |
puts "Serving HTTP on port #{@port}" | |
loop{ | |
Thread.start(@socket.accept) do | client | | |
request = client.gets | |
puts request | |
method, file, ver = request.split(' ') | |
if file == "/" or file == "/favicon.ico" or not File.file?(file) | |
client.puts "Wrong HTTP Request" | |
else | |
client.puts File.read(".#{file}") | |
if @remove | |
File.delete(".#{file}") | |
end | |
end | |
client.close | |
end | |
} | |
end | |
end | |
server = WebServer.new(8080, true) | |
server.mainloop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment