class Docwatch::Session
Public Class Methods
new(socket, logger)
click to toggle source
# File lib/docwatch/session.rb, line 3 def initialize(socket, logger) @socket = socket @logger = logger logger.log first_request_line end
Public Instance Methods
close()
click to toggle source
# File lib/docwatch/session.rb, line 10 def close @socket.close end
path()
click to toggle source
# File lib/docwatch/session.rb, line 14 def path if first_request_line.nil? || first_request_line.length == 0 return end first_request_line.split(' ')[1] end
respond_with(code, str, content_type)
click to toggle source
# File lib/docwatch/session.rb, line 34 def respond_with(code, str, content_type) println 'HTTP/1.1 %d' % code println 'Content-Type: %s; charset=utf8' % content_type println println str close end
respond_with_404()
click to toggle source
# File lib/docwatch/session.rb, line 30 def respond_with_404 respond_with(404, 'Not Found', 'text/html') end
respond_with_html(str)
click to toggle source
# File lib/docwatch/session.rb, line 26 def respond_with_html(str) respond_with(200, str, 'text/html') end
respond_with_text(str)
click to toggle source
# File lib/docwatch/session.rb, line 22 def respond_with_text(str) respond_with(200, str, 'text/plain') end
Private Instance Methods
first_request_line()
click to toggle source
# File lib/docwatch/session.rb, line 51 def first_request_line input_lines.each(&:chomp).first end
input_lines()
click to toggle source
# File lib/docwatch/session.rb, line 45 def input_lines @input_lines ||= @socket.recvmsg[0].lines rescue [] end
print(msg)
click to toggle source
# File lib/docwatch/session.rb, line 55 def print(msg) @socket.print msg rescue nil end
println(msg = '')
click to toggle source
# File lib/docwatch/session.rb, line 59 def println(msg = '') print msg + "\r\n" end