Sha256: ed1b90e7bb60b2f1509a335b4d357c5551ce0564cca38c56ce573913bf95b081

Contents?: true

Size: 586 Bytes

Versions: 2

Compression:

Stored size: 586 Bytes

Contents

#!/usr/bin/env ruby

require 'socket'

server = TCPServer.new 1337

loop do
  client = server.accept
  request = clients.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.5 bin/server
erik_server-0.0.1 bin/server