Class: Carnivore::Source::Http

Inherits:
HttpSource show all
Defined in:
lib/carnivore-http/http.rb

Direct Known Subclasses

HttpEndpoints

Constant Summary

Constants inherited from HttpSource

Carnivore::Source::HttpSource::BODY_TO_FILE_SIZE

Instance Attribute Summary

Attributes inherited from HttpSource

#args, #auth_allowed_origins, #auth_htpasswd

Instance Method Summary collapse

Methods inherited from HttpSource

#allowed_credentials?, #allowed_htpasswd?, #allowed_origin?, #authorized?, #auto_process?, #build_listener, #build_message, #confirm, #default_args, #perform_transmission, #retry_delivery, #retry_directory, #retry_write_directory, #setup, #terminate, #transmit, #write_for_retry

Methods included from Http::Utils::Params

#dump_query_string, #format_query_args, #format_query_type, included, #parse_query_string

Instance Method Details

#process(*process_args) ⇒ Object

Process requests



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/carnivore-http/http.rb', line 8

def process(*process_args)
  unless(@processing)
    @processing = true
    srv = build_listener do |req|
      begin
        msg = build_message(req)
        msg = format(msg)
        if(authorized?(msg))
          callbacks.each do |name|
            c_name = callback_name(name)
            debug "Dispatching #{msg} to callback<#{name} (#{c_name})>"
            callback_supervisor[c_name].call(msg)
          end
          req.respond(:ok, 'So long, and thanks for all the fish!') if args[:auto_respond]
        else
          req.respond(:unauthorized, 'You are not authorized to perform requested action!')
        end
      rescue => e
        req.respond(:bad_request, "Failed to process request -> #{e}")
      end
    end
    true
  else
    false
  end
end