2011-11-08 36 views
1

我找不到Active Resource發起連接的地方。我曾期待Connection.request調用網絡庫,但它只是調用ActiveSupport :: Notifications.instrument,它似乎是某種消息服務。Active Resource在何處以及如何執行其HTTP請求?

有沒有人知道這是如何工作的?我無法找到正在偵聽郵件的代碼。 ActiveSupport :: Notifications對我來說是全新的,因此可能有一個顯而易見的位置,即偵聽器所在的位置。

def request(method, path, *arguments) 
    result = ActiveSupport::Notifications.instrument("request.active_resource") do |payload| 
     payload[:method]  = method 
     payload[:request_uri] = "#{site.scheme}://#{site.host}:#{site.port}#{path}" 
     payload[:result]  = http.send(method, path, *arguments) 
    end 

的方法定義爲here在GitHub上

回答

1

我相信答案在於,被分配到payload[:result]http.send()電話。

從文件中進一步:

# Creates new Net::HTTP instance for communication with the 
    # remote service and resources. 
    def http 
    configure_http(new_http) 
    end 

    def new_http 
    if @proxy 
     Net::HTTP.new(@site.host, @site.port, @proxy.host, @proxy.port, @proxy.user, @proxy.password) 
    else 
     Net::HTTP.new(@site.host, @site.port) 
    end 
    end 

    def configure_http(http) 
    http = apply_ssl_options(http) 

    # Net::HTTP timeouts default to 60 seconds. 
    if @timeout 
     http.open_timeout = @timeout 
     http.read_timeout = @timeout 
    end 

    http 
    end 

Net::HTTP來自require 'net/https'從線4

+0

感謝。回想起來這似乎很明顯!我一定被ActiveSupport :: Notifications.instrument調用分心了。然而,它留下了什麼樣的儀器實際上對塊做什麼的問題。它是否立即執行? –

相關問題