Sha256: c558a39702fec5e2bb4a7e9fd1161b7f86ef1d2c2f77885a6f5b32a28e15678f
Contents?: true
Size: 1.4 KB
Versions: 8
Compression:
Stored size: 1.4 KB
Contents
module Dragonfly class SimpleEndpoint include Loggable # Instance methods def initialize(app) @app = app use_same_log_as(app) end def call(env) request = Rack::Request.new(env) case request.path_info when '', '/', app.url_path_prefix dragonfly_response else job = Job.from_path(request.path_info, app) job.validate_sha!(request['s']) if app.protect_from_dos_attacks Response.new(job, env).to_response end rescue Serializer::BadString, Job::InvalidArray => e log.warn(e.message) [404, {'Content-Type' => 'text/plain'}, ['Not found']] rescue Job::NoSHAGiven => e [400, {"Content-Type" => 'text/plain'}, ["You need to give a SHA parameter"]] rescue Job::IncorrectSHA => e [400, {"Content-Type" => 'text/plain'}, ["The SHA parameter you gave (#{e}) is incorrect"]] end def required_params_for(job) {'s' => job.sha} end private attr_reader :app def dragonfly_response body = <<-DRAGONFLY _o|o_ _~~---._( )_.---~~_ ( . \\ / . ) `-.~--' |=| '--~.-' _~-.~'" /|=|\\ "'~.-~_ ( ./ |=| \\. ) `~~`"` |=| `"'ME" |-| <-> V DRAGONFLY [200, { 'Content-Type' => 'text/plain', 'Content-Size' => body.bytesize.to_s }, [body] ] end end end
Version data entries
8 entries across 8 versions & 2 rubygems