Class: Docwatch::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/docwatch/session.rb

Instance Method Summary collapse

Constructor Details

#initialize(socket, logger) ⇒ Session

Returns a new instance of Session.



3
4
5
6
7
8
# File 'lib/docwatch/session.rb', line 3

def initialize(socket, logger)
    @socket = socket
    @logger = logger

    logger.log(first_request_line)
end

Instance Method Details

#closeObject



10
11
12
# File 'lib/docwatch/session.rb', line 10

def close
    @socket.close
end

#pathObject



14
15
16
17
18
19
20
# 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) ⇒ Object



34
35
36
37
38
39
40
41
# 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_404Object



30
31
32
# File 'lib/docwatch/session.rb', line 30

def respond_with_404
    respond_with(404, 'Not Found', 'text/html')
end

#respond_with_html(str) ⇒ Object



26
27
28
# File 'lib/docwatch/session.rb', line 26

def respond_with_html(str)
    respond_with(200, str, 'text/html')
end

#respond_with_text(str) ⇒ Object



22
23
24
# File 'lib/docwatch/session.rb', line 22

def respond_with_text(str)
    respond_with(200, str, 'text/plain')
end