varnisher 1.0.beta.4 → 1.0.beta.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/bin/varnisher +2 -1
- data/lib/varnisher.rb +3 -1
- data/lib/varnisher/domainpurger.rb +15 -4
- data/lib/varnisher/pagepurger.rb +3 -1
- data/lib/varnisher/purger.rb +29 -5
- data/lib/varnisher/spider.rb +1 -0
- data/lib/varnisher/version.rb +1 -1
- metadata +58 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0b5fd6898bd69ebb046e5b5ca5459ca0fd66ebb
|
4
|
+
data.tar.gz: cef950689b3c66b79ec4095b5508080ec2cc7ccf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8068e477b2d6dc4bebaa2d908595c4728ad104447ea979ed829fd560ef8b700e4e605ebabadfcfae9bb3eba5044786a7aedff14ba8bc0788f140fa5dabdac8d
|
7
|
+
data.tar.gz: ce25a130d9709f8a6304e73e6e26bdbf69433992ed768c824be10b815f07ed74817d5b049b6f60b9939d13b9cdb67fe91504077c2d3dea593868dcbe09105437
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# varnisher
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/robmiller/varnisher.png?branch=master)](https://travis-ci.org/robmiller/varnisher)
|
4
|
+
|
3
5
|
Administering Varnish is generally a breeze, but sometimes you want to
|
4
6
|
do one of the few things that aren't painless out of the box. Hopefully,
|
5
7
|
that's where this toolbox comes in.
|
data/bin/varnisher
CHANGED
@@ -59,7 +59,8 @@ Main {
|
|
59
59
|
purger.purge
|
60
60
|
# If target is a hostname, assume we want to purge an entire domain.
|
61
61
|
elsif target =~ /^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$/
|
62
|
-
Varnisher::DomainPurger.new target
|
62
|
+
purger = Varnisher::DomainPurger.new target
|
63
|
+
purger.purge
|
63
64
|
|
64
65
|
if params['reindex'].given?
|
65
66
|
spider = Varnisher::Spider.new "http://#{target}/"
|
data/lib/varnisher.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
1
3
|
require_relative 'varnisher/spider'
|
2
4
|
require_relative 'varnisher/purger'
|
3
5
|
require_relative 'varnisher/domainpurger'
|
@@ -30,7 +32,7 @@ module Varnisher
|
|
30
32
|
end
|
31
33
|
|
32
34
|
def self.options=(options)
|
33
|
-
@options = options
|
35
|
+
@options = @options.merge(options)
|
34
36
|
|
35
37
|
if options['hostname'].nil? && options['target']
|
36
38
|
uri = URI.parse(options['target'])
|
@@ -12,16 +12,27 @@ module Varnisher
|
|
12
12
|
# }
|
13
13
|
# }
|
14
14
|
class DomainPurger
|
15
|
-
#
|
15
|
+
# Initialises the purger
|
16
16
|
#
|
17
17
|
# @param domain [String] The hostname to purge
|
18
18
|
def initialize(domain)
|
19
|
-
|
19
|
+
@domain = domain
|
20
|
+
end
|
21
|
+
|
22
|
+
# Executes the purge request
|
23
|
+
#
|
24
|
+
# @return [True, False] True of the purge was successful, false if
|
25
|
+
# it wasn't
|
26
|
+
def purge
|
27
|
+
purged = Varnisher.purge(@domain, :domain)
|
28
|
+
|
20
29
|
if purged
|
21
|
-
Varnisher.log.info "Purged #{domain}"
|
30
|
+
Varnisher.log.info "Purged #{@domain}"
|
22
31
|
else
|
23
|
-
Varnisher.log.info "Failed to purge #{domain}"
|
32
|
+
Varnisher.log.info "Failed to purge #{@domain}"
|
24
33
|
end
|
34
|
+
|
35
|
+
purged
|
25
36
|
end
|
26
37
|
end
|
27
38
|
end
|
data/lib/varnisher/pagepurger.rb
CHANGED
@@ -6,8 +6,10 @@ require 'parallel'
|
|
6
6
|
module Varnisher
|
7
7
|
# Purges an individual URL from Varnish.
|
8
8
|
class PagePurger
|
9
|
+
attr_reader :urls
|
10
|
+
|
9
11
|
# A bash at an abstract representation of resources. All you need
|
10
|
-
# is
|
12
|
+
# is a selector, and what attribute to select from the matched
|
11
13
|
# elements.
|
12
14
|
Resource = Struct.new :name, :selector, :attribute
|
13
15
|
def self.resources
|
data/lib/varnisher/purger.rb
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
# Adds the custom verb "PURGE" to the Net::HTTP library, allowing calls
|
2
|
+
# to:
|
3
|
+
#
|
4
|
+
# Net::HTTP.new(host, port).request(Purge.new(uri))
|
5
|
+
class Purge < Net::HTTPRequest
|
6
|
+
METHOD = "PURGE"
|
7
|
+
REQUEST_HAS_BODY = false
|
8
|
+
RESPONSE_HAS_BODY = false
|
9
|
+
end
|
10
|
+
|
11
|
+
# Adds the custom verb "DOMAINPURGE" to the Net::HTTP library, allowing
|
12
|
+
# calls to:
|
13
|
+
#
|
14
|
+
# Net::HTTP.new(host, port).request(DomainPurge.new(uri))
|
15
|
+
class DomainPurge < Net::HTTPRequest
|
16
|
+
METHOD = "DOMAINPURGE"
|
17
|
+
REQUEST_HAS_BODY = false
|
18
|
+
RESPONSE_HAS_BODY = false
|
19
|
+
end
|
20
|
+
|
1
21
|
module Varnisher
|
2
22
|
# Sends a purge request to the Varnish server
|
3
23
|
#
|
@@ -34,7 +54,7 @@ module Varnisher
|
|
34
54
|
# use "/"
|
35
55
|
# @param host [String] The hostname of the URL being purged
|
36
56
|
def initialize(method, path, host)
|
37
|
-
@
|
57
|
+
@request_method = method == "PURGE" ? Purge : DomainPurge
|
38
58
|
@path = path
|
39
59
|
@host = host
|
40
60
|
end
|
@@ -50,13 +70,17 @@ module Varnisher
|
|
50
70
|
end
|
51
71
|
|
52
72
|
def send
|
53
|
-
hostname = Varnisher.options['hostname']
|
73
|
+
hostname = Varnisher.options['hostname'] || @host
|
54
74
|
port = Varnisher.options['port']
|
55
75
|
|
56
|
-
|
57
|
-
|
58
|
-
|
76
|
+
begin
|
77
|
+
http = Net::HTTP.new(hostname, port)
|
78
|
+
response = http.request(@request_method.new(@path))
|
79
|
+
rescue Timeout::Error
|
80
|
+
return false
|
59
81
|
end
|
82
|
+
|
83
|
+
response.code == "200"
|
60
84
|
end
|
61
85
|
end
|
62
86
|
end
|
data/lib/varnisher/spider.rb
CHANGED
data/lib/varnisher/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: varnisher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.beta.
|
4
|
+
version: 1.0.beta.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Miller
|
@@ -52,6 +52,62 @@ dependencies:
|
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.7.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 10.1.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 10.1.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 5.0.6
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 5.0.6
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.13.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.13.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: letters
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.4.1
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.4.1
|
55
111
|
description: Some tools that make working with the Varnish HTTP cache easier, including
|
56
112
|
things like doing mass purges of entire domains.
|
57
113
|
email: rob@bigfish.co.uk
|
@@ -95,3 +151,4 @@ signing_key:
|
|
95
151
|
specification_version: 4
|
96
152
|
summary: Helpful tools for working with Varnish caches
|
97
153
|
test_files: []
|
154
|
+
has_rdoc:
|