trying 'PURGE' varnish using curb
我正在尝试使用\\'curb \\'gem向我们的清漆盒发送\\'PURGE \\'请求,问题是它似乎不起作用。
我无法确定它是否失败,因为它没有在我们的清漆盒中实现(应该已经实现),或者因为遏制没有将请求作为清除发送而是作为获取。
这实际上是发出请求的功能:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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为此函数返回的值:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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 \\'请求,具体是:
1 2 3 4 5 6 7 8 | # see lib/curl.rb module Curl # ... def self.patch(url, params={}, &block) http :PATCH, url, postalize(params), nil, &block end # ... end |
原来是清漆后端,需要对其进行重新工具化以禁止使用而不是清除,需要使之正常工作,但最终我的代码还可以。