trying 'PURGE' varnish using curb

161 views Asked by At

I'm trying to use the 'curb' gem to send a 'PURGE' request to our varnish box, the problem is that It doesn't seem to work.

I can't tell if it's failing because it's not been implemented in our varnish box(it's supposed to have been) or because curb isn't sending the request as a purge but rather as a get.

Here's the function that actually makes the request:

    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

when run (with the IP of two varnish boxes) I get this:

  • 200
  • 200
  • true

with true being the value returned by this function:

        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

I've tried using this answer to send a 'PURGE' request, specifically:

# see lib/curl.rb
module Curl
  # ...
  def self.patch(url, params={}, &block)
    http :PATCH, url, postalize(params), nil, &block
  end
  # ...
end
1

There are 1 answers

0
Thermatix On BEST ANSWER

Turns out it was the varnish backend, need to re-tool it to take bans rather than purges, need to get that working but ultimately my code is fine.