Class: RightDevelop::Testing::Server::MightApi::App::Echo
- Defined in:
- lib/right_develop/testing/servers/might_api/app/echo.rb
Overview
Implements an echo service.
Constant Summary collapse
- METADATA_CLASS =
metadata
::RightDevelop::Testing::Recording::Metadata
Constants inherited from Base
Base::DEFAULT_PROXY_SETTINGS, Base::MAX_REDIRECTS, Base::MUTEX
Instance Attribute Summary
Attributes inherited from Base
#config, #logger, #state_file_path
Instance Method Summary collapse
- #handle_request(env, verb, uri, headers, body) ⇒ Object
-
#initialize(options = {}) ⇒ Echo
constructor
A new instance of Echo.
Methods inherited from Base
app_threads, #call, #cleanup, interrupted=, interrupted?
Constructor Details
#initialize(options = {}) ⇒ Echo
Returns a new instance of Echo.
34 35 36 37 |
# File 'lib/right_develop/testing/servers/might_api/app/echo.rb', line 34 def initialize( = {}) super fail "Unexpected mode: #{config.mode}" unless config.mode == :echo end |
Instance Method Details
#handle_request(env, verb, uri, headers, body) ⇒ 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/right_develop/testing/servers/might_api/app/echo.rb', line 40 def handle_request(env, verb, uri, headers, body) # echo request back as response. response = ::Rack::Response.new response.write "verb = #{verb.inspect}\n\n" response.write "uri = #{uri}\n\n" response.write "headers = #{METADATA_CLASS.deep_sorted_json(headers, true)}\n\n" response.write "body = #{body.inspect}\n\n" # check routes. if route = find_route(uri) route_path, route_data = route response.write "URL matched #{route_data[:name].inspect}\n\n" # compute effective metadata for request. begin proxied_url = ::File.join(route_data[:url], uri.path) unless uri.query.to_s.empty? proxied_url << '?' << uri.query end = METADATA_CLASS.new( mode: :echo, kind: :request, logger: logger, route_data: route_data, uri: METADATA_CLASS.normalize_uri(proxied_url), verb: verb, headers: headers, body: body, variables: {}) # echo any interesting metadata. response.write "substituted request variables = #{METADATA_CLASS.deep_sorted_json(.variables, true)}\n\n" response.write "effective route configuration = #{METADATA_CLASS.deep_sorted_json(.effective_route_config, true)}\n\n" response.write "request checksum = #{.checksum}\n\n" rescue Exception => e response.write "Failure to compute request metadata:\n#{e.class}: #{e.}\n#{(e.backtrace || []).join("\n")}\n\n" end else response.write "Failed to match any route. The following routes are valid:\n\n" config.routes.keys.each do |prefix| response.write "Prefix = #{prefix.inspect}\n\n" end end # process details. response.write "ruby %sp%s\n\n" % [RUBY_VERSION, RUBY_PATCHLEVEL] response.write "Raw configuration = #{::JSON.pretty_generate(config.to_hash)}\n\n" # hash order is significant in config config.routes.each do |route_path, route_config| response.write "=== Compiled route matchers begin for root = #{route_path.inspect}:\nmatchers = {\n" (route_config[METADATA_CLASS::MATCHERS_KEY] || {}).each do |regex, route_data| response.write " #{regex.inspect} =>\n #{route_data.inspect},\n" end response.write "}\n=== Compiled route matchers end.\n\n" end response.write "env = #{METADATA_CLASS.deep_sorted_json(env, true)}\n\n" response.write "ENV = #{METADATA_CLASS.deep_sorted_json(::ENV, true)}\n\n" response.finish end |