Sha256: 8e17a726d27a69475a190b1673e046664c82a6a4b1bb869c093412d3c776673f

Contents?: true

Size: 585 Bytes

Versions: 2

Compression:

Stored size: 585 Bytes

Contents

#!/usr/bin/env ruby

require 'socket'

server = TCPServer.new 1337

loop do
  client = server.accept
  request = client.gets
  verb, path,protocol = request.spilt(" ")
  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

2 entries across 2 versions & 1 rubygems

Version Path
erik_server-0.0.7 bin/erik_server
erik_server-0.0.6 bin/server