我正在尝试使用'curb' gem 向我们的清漆盒发送'PURGE' 请求,问题是它似乎不起作用。
我不知道它是否失败是因为它没有在我们的清漆盒中实现(它应该已经实现了),或者是因为遏制发送请求不是作为清除而是作为获取。
这是实际发出请求的函数:
def make_request_of (request_method)
self.curl = Curl::Easy.new(self.uri) do |http|
setup_request request_method, http
end
self.curl.ssl_verify_peer = self.ssl ||false
self.curl.http request_method
if self.curl.response_code == 301
self.uri = self.curl.redirect_url
make_request_of request_method
end
end
def setup_request method,http
http.headers['request-method'] = method.to_s
http.headers.update(headers)
http.max_redirects = self.redirects || 3
http.post_body = self.payload || nil
http.http_auth_types = self.auth_type || nil
http.username = self.username || nil
http.password = self.password || nil
http.useragent = "curb"
http
end
运行时(使用两个清漆盒的 IP)我得到这个:
- 200
- 200
- 真的
true 是此函数返回的值:
def flush pattern
results = ::YAML.load_file(self.varnish_ip_files_path).map do |ip|
http = VCK::Http.request do
set_uri "http://#{ip}/#{pattern}"
end
http.make_request_of 'PURGE'
puts http.response
case http.response
when 200
true
else
false
end
end
!(results.reject! { |r| r }.length >= 1)
end
我尝试使用此答案发送“PURGE”请求,特别是:
# see lib/curl.rb
module Curl
# ...
def self.patch(url, params={}, &block)
http :PATCH, url, postalize(params), nil, &block
end
# ...
end