Class: Devproxy::CLI::Server::Servlet

Inherits:
WEBrick::HTTPServlet::AbstractServlet
  • Object
show all
Defined in:
lib/devproxy/cli/server.rb

Instance Method Summary collapse

Instance Method Details

#do_GET(request, response) ⇒ Object



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
# File 'lib/devproxy/cli/server.rb', line 5

def do_GET(request,response)
  token   = request.cookies.detect { |x| x.name == "DEVPROXY" }
  token &&= token.value
  token ||= "none"
  sysname = "#{%x{whoami}}@#{%x{hostname}}"

  response.status          = 200
  response['Content-Type'] = "text/html"
  response.body = %{
    <html>
    <head>
      <link rel="stylesheet" href="/css/style.css">
      <title>Devproxy Test Server</title>
    </head>
    <body>
      <h1>Hello from #{h(sysname)}</h2>
      <div class="details">
        <table>
          <caption>Tunnel Details</caption>
          <tbody>
            <tr>
              <td>host</td><td>#{h(request.host)}</td>
            </tr>
            <tr>
              <td>protocol</td><td>#{h(request['x-forwarded-proto'])}</td>
            </tr>
            <tr>
              <td>token</td><td>#{h(token)}</td>
            </tr>
          </tbody>
        </table>
      </div>
    </body>
    </html>
  }
end

#do_POST(request, response) ⇒ Object



41
42
43
# File 'lib/devproxy/cli/server.rb', line 41

def do_POST(request,response)
  do_GET(request,response)
end

#h(str) ⇒ Object



44
45
46
# File 'lib/devproxy/cli/server.rb', line 44

def h(str)
  CGI::escapeHTML(str || "")
end