Class: Nuri::Server::Handler
- Inherits:
-
WEBrick::HTTPServlet::AbstractServlet
- Object
- WEBrick::HTTPServlet::AbstractServlet
- Nuri::Server::Handler
- Defined in:
- lib/nuri/server.rb
Instance Method Summary collapse
- #do_GET(request, response) ⇒ Object
- #do_POST(request, response) ⇒ Object
- #do_PUT(request, response) ⇒ Object
-
#initialize(server, master, logger) ⇒ Handler
constructor
A new instance of Handler.
- #trusted(address) ⇒ Object
Constructor Details
#initialize(server, master, logger) ⇒ Handler
Returns a new instance of Handler.
158 159 160 161 |
# File 'lib/nuri/server.rb', line 158 def initialize(server, master, logger) @master = master @logger = logger end |
Instance Method Details
#do_GET(request, response) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/nuri/server.rb', line 163 def do_GET(request, response) status = 400 content_type, body = '' if not trusted(request.peeraddr[2]) status = 403 else path = (request.path[-1,1] == '/' ? request.path.chop : request.path) if path == '/model' status, content_type, body = [200, 'text/plain', @master.get_model(:json => true)] elsif path == '/log' status, content_type, body = [200, 'text/plain', @master.get_log(100)] end end response.status = status response['Content-Type'] = content_type response.body = body end |
#do_POST(request, response) ⇒ Object
183 184 185 186 187 188 189 190 |
# File 'lib/nuri/server.rb', line 183 def do_POST(request, response) status = 400 content_type, body = '' response.status = status response['Content-Type'] = content_type response.body = body end |
#do_PUT(request, response) ⇒ Object
192 193 194 195 196 197 198 199 |
# File 'lib/nuri/server.rb', line 192 def do_PUT(request, response) status = 400 content_type, body = '' response.status = status response['Content-Type'] = content_type response.body = body end |
#trusted(address) ⇒ Object
201 202 203 204 |
# File 'lib/nuri/server.rb', line 201 def trusted(address) # TODO true end |