Method: #handle_request

Defined in:
lib/easel/server.rb

#handle_request(socket) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/easel/server.rb', line 40

def handle_request socket

  log_info "Receieved request: #{socket}"
  request = read_HTTP_message socket

  # TODO: check what the minimum allow handling is. I think there's one more method I need to handle.
  case request[:method]
  when "GET"
    # TODO: respond with app, css file, favicon, or 404 error.
    if request[:fields][:Upgrade] == "websocket\r\n"
      run_websocket(socket, request)
    else
        handle_get(socket, request)
    end
  #when "HEAD"
    # TODO: Deal with HEAD request. https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4
  else
    # TODO: respond with an appropriate error.
    response "I don't understand what you sent - go away."
    socket.print "HTTP/1.1 200 OK\r\n" +
                 "Content-Type: text/plain\r\n" +
                 "Content-Length: #{response.bytesize}\r\n" +
                 "Connection: close\r\n" +
                 "\r\n" +
                 response
    socket.close
  end

end