Class: Varnish::Client
- Inherits:
-
Object
- Object
- Varnish::Client
- Defined in:
- lib/varnish/client.rb
Defined Under Namespace
Instance Method Summary collapse
- #ban(cmd) ⇒ Object
- #fetch(path, headers = {}) ⇒ Object
-
#initialize(host, port, target) ⇒ Client
constructor
A new instance of Client.
- #purge(cmd) ⇒ Object
Constructor Details
#initialize(host, port, target) ⇒ Client
Returns a new instance of Client.
5 6 7 8 |
# File 'lib/varnish/client.rb', line 5 def initialize(host, port, target) @http = Net::HTTP.new(host, port) @target = URI.parse(target.to_s) end |
Instance Method Details
#ban(cmd) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/varnish/client.rb', line 17 def ban(cmd) req = Ban.new(cmd) req['Host'] = @target.host res = @http.request(req) res.code == '200' end |
#fetch(path, headers = {}) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/varnish/client.rb', line 24 def fetch(path, headers = {}) req = Net::HTTP::Get.new(path, headers) req['Host'] = @target.host res = @http.request(req) return nil unless res.code == '200' res.body end |