Class: WebFetch::Server

Inherits:
EM::Connection
  • Object
show all
Includes:
EM::HttpServer, EventMachineHelpers, HTTPHelpers
Defined in:
lib/web_fetch/server.rb

Overview

Web server that accepts requests to gather and retrieve external HTTP requests

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EventMachineHelpers

#apply_callbacks, #request_async, #tick_loop, #wait_for_response

Methods included from HTTPHelpers

#accept_gzip?, #compress, #default_headers, #fail_, #failure, #pending, #post_data, #request_params, #respond_immediately, #succeed, #success

Instance Attribute Details

#storageObject (readonly)

Returns the value of attribute storage.



7
8
9
# File 'lib/web_fetch/server.rb', line 7

def storage
  @storage
end

Instance Method Details

#gather(targets) ⇒ Object

Note that #gather is called by WebFetch itself to asynchronously gather the required HTTP objects. All public API requests go via #process_http_request and subsequently WebFetch::Router#route



30
31
32
33
34
35
36
37
# File 'lib/web_fetch/server.rb', line 30

def gather(targets)
  targets.each do |target|
    http = request_async(target[:request])
    request = { uid: target[:uid], deferred: http }
    apply_callbacks(request)
    @storage.store(target[:uid], request)
  end
end

#post_initObject



13
14
15
16
17
18
# File 'lib/web_fetch/server.rb', line 13

def post_init
  super
  @router = Router.new
  @storage = Storage
  no_environment_strings
end

#process_http_requestObject



20
21
22
23
24
25
# File 'lib/web_fetch/server.rb', line 20

def process_http_request
  result = @router.route(@http_request_uri, request_params)
  response = EM::DelegatedHttpResponse.new(self)
  default_headers(response)
  outcome(result, response)
end