class SerialportServer::HttpServer

Public Instance Methods

process_http_request() click to toggle source
# File lib/serialport-server/http_server.rb, line 5
def process_http_request
  res = EM::DelegatedHttpResponse.new(self)
  puts "[http] #{@http_request_method} #{@http_path_info} #{@http_query_string} #{@http_post_content}"
  res.headers['Access-Control-Allow-Origin'] = '*'
  res.headers['Access-Control-Allow-Headers'] = 'Content-Type'
  res.headers['Access-Control-Allow-Methods'] = 'PUT,DELETE,POST,GET,OPTIONS'
  if @http_request_method == 'GET'
    res.status = 200
    res.content = SerialportServer.application.recvs.to_json
    res.send_response
  elsif @http_request_method == 'POST'
    res.status = 200
    SerialportServer.application.serialport.puts @http_post_content
    res.content = SerialportServer.application.recvs.to_json
    res.send_response
  end
end