Sha256: 0aa87f17c5569733a5a321d0dc562f755138e5120169d478c007d70ebda01ad5

Contents?: true

Size: 586 Bytes

Versions: 1

Compression:

Stored size: 586 Bytes

Contents

#!/usr/bin/env ruby

require 'socket'

server = TCPServer.new 1337

loop do
  client = server.accept
  request = client.gets
  verb, path, protocol = request.split(" ")
  path ="." + path

  if File.file?(path)
    body = File.open(path, "r"){|file| file.read}
    status = "200 OK"
  else
    body = "File not found\n"
    status = "404 Not Found"
  end

  response = "#{protocol} #{status}\n"
  response += "Content-Type: text/html\n"
  response += "Content-Length: #{body.length}\n"
  response += "Connection: close\n\n"
  response += body

  client.puts response
  client.close
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
erik_server-0.0.8 bin/erik_server