Class: RScriptServer
- Inherits:
-
Object
- Object
- RScriptServer
- Includes:
- AppRoutes, REXML
- Defined in:
- lib/rscript-server.rb
Instance Method Summary collapse
-
#initialize(raw_opts = {}) ⇒ RScriptServer
constructor
A new instance of RScriptServer.
- #start ⇒ Object
Constructor Details
#initialize(raw_opts = {}) ⇒ RScriptServer
Returns a new instance of RScriptServer.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rscript-server.rb', line 14 def initialize(raw_opts={}) opts = {ip: '0.0.0.0', port: 4446, pkg_src: ''}.merge(raw_opts) @ip, @port, @url_base = opts[:ip], opts[:port], opts[:pkg_src] super() #@app = AppRoutes.new(params) routes(@params) @rscript = RScript.new() @content_type = 'text/html' end |
Instance Method Details
#start ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rscript-server.rb', line 28 def start server = TCPServer.new(@ip, @port) while (session = server.accept) raw_request = session.gets request = raw_request[/.[^\s]+(?= HTTP\/1\.\d)/].strip puts "%s %s" % [Time.now,request] result = run_route(request) result ||= "404: page not found" session.print "HTTP/1.1 200/OK\r\nContent-type: #{@content_type}; charset=utf-8\r\n\r\n" session.print result session.close end end |