Class: Maze::Servlets::ErrorConfigServlet
- Inherits:
-
BaseServlet
- Object
- WEBrick::HTTPServlet::AbstractServlet
- BaseServlet
- Maze::Servlets::ErrorConfigServlet
- Defined in:
- lib/maze/servlets/error_config_servlet.rb
Overview
Allows clients to request error configs that have been added to the queue.
Constant Summary collapse
- BAD_REQUEST_BODY =
'{ "type":"about:blank", "title":"Bad Request", "status":400, "detail":"Maze Runner has not been given an error config to return" }'
Instance Method Summary collapse
-
#do_GET(request, response) ⇒ Object
Captures the details of the request for checking and serves the next error config, if there is one.
-
#do_OPTIONS(request, response) ⇒ Object
Logs and returns a set of valid headers for this servlet.
Instance Method Details
#do_GET(request, response) ⇒ Object
Captures the details of the request for checking and serves the next error config, if there is one.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/maze/servlets/error_config_servlet.rb', line 22 def do_GET(request, response) if Server.error_configs.size_remaining > 0 # Server the next error config in the queue error_config = Server.error_configs.current error_config[:headers].each do |key, value| response.header[key] = value end response.body = error_config[:body] response.status = error_config[:status] Server.error_configs.next else # Log and return an error $logger.error 'Error config requested but none are queued - returning 400 Bad Request' response.body = BAD_REQUEST_BODY response.status = 400 end response.header['Content-Type'] = 'application/json' # Store the query parameters in the error config request list details = { body: {}, query: Rack::Utils.parse_nested_query(request.query_string), request_uri: request.request_uri, request: request, response: response, method: 'GET' } Server.error_config_requests.add(details) end |
#do_OPTIONS(request, response) ⇒ Object
Logs and returns a set of valid headers for this servlet.
58 59 60 61 62 63 |
# File 'lib/maze/servlets/error_config_servlet.rb', line 58 def do_OPTIONS(request, response) super response.header['Access-Control-Allow-Methods'] = 'GET, OPTIONS' response.status = Server.status_code('OPTIONS') end |