File: HttpEchoServer.rb

package info (click to toggle)
ruby-eserver 0.1.1-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 40 kB
  • ctags: 22
  • sloc: ruby: 178; makefile: 40
file content (40 lines) | stat: -rw-r--r-- 861 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Copyright (C) 2001 John W. Small All Rights Reserved
# mailto:jsmall@laser.net  subject:ruby-generic-server
# Freeware

require 'GServer'
require 'timeout'

class HttpEchoServer < GServer

  def serve(io)
    io.puts("HTTP/1.0 200 Echo follows!")
    io.puts("Connection: close")
    io.puts("Content-Type: text/html")
    io.puts
    io.puts("<html><body>")
    io.puts("<H1>HTTP/1.0 200 Echo follows!</H1>")
    begin
      timeout(1) {
        io.each_line { |line|
          line.chomp!
          io.puts("#{line}<br>")
        }
      }
    rescue
    ensure
      io.puts("</body></html>")
    end
  end

  def initialize(port=8080, host = GServer::DEFAULT_HOST,
    maxConnections = 4, stdlog = $stderr,
    audit = true, debug = true)
    super
  end

end

if __FILE__ == $0
  HttpEchoServer.new.start.join
end