cachewarp 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +11 -0
- data/cachewarp.gemspec +23 -0
- data/lib/cachewarp.rb +40 -0
- data/lib/cachewarp/version.rb +1 -0
- data/lib/cachewarp/web_service.rb +29 -0
- data/test/lib/cachewarp/akamai_test.rb +10 -0
- data/test/lib/cachewarp/version_test.rb +7 -0
- data/test/test_helper.rb +4 -0
- data/thanks.txt +5 -0
- metadata +102 -0
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 codeweft
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# CacheWarp
|
2
|
+
|
3
|
+
Gem targeted towards providing a solution to verify cache headers for content delivery services like Akamai
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
require 'cachewarp' #Require CacheWarp in your file
|
8
|
+
request = CacheWarp.new('http://www.akamai.com/') #Initialize Request Object
|
9
|
+
request.fetch #Fetch Request
|
10
|
+
request.response_headers #Get Response Headers
|
11
|
+
request.is_cached? #Verify 'TCP HIT' i.e if Akamai is caching the request
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Using Bundler
|
16
|
+
|
17
|
+
gem 'cachewarp' #Add to Gemfile
|
18
|
+
$ bundle #Install Gem
|
19
|
+
|
20
|
+
Using gem command
|
21
|
+
|
22
|
+
$ gem install cachewarp
|
23
|
+
|
24
|
+
#Change Log:
|
25
|
+
|
26
|
+
0.0.1
|
27
|
+
Provision to verify TCP HIT in Akamai cache
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/cachewarp.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cachewarp/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cachewarp"
|
8
|
+
spec.version = GEM_VERSION
|
9
|
+
spec.authors = ["codeweft", "bitweft", "juteroot"]
|
10
|
+
spec.email = ["juteroot@gmail.com"]
|
11
|
+
spec.description = %q{Gem to verify cache and content delivery headers}
|
12
|
+
spec.summary = %q{Gem to verify cache and content delivery headers}
|
13
|
+
spec.homepage = "http://www.juteroot.com"
|
14
|
+
spec.license = "To be decided"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/lib/cachewarp.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative 'cachewarp/version'
|
2
|
+
require_relative 'cachewarp/web_service'
|
3
|
+
|
4
|
+
class CacheWarp < WebService
|
5
|
+
attr_reader :uri, :response_headers, :headers, :failures
|
6
|
+
|
7
|
+
def initialize uri=nil
|
8
|
+
@uri = uri
|
9
|
+
@headers =
|
10
|
+
{
|
11
|
+
'Pragma' => 'akamai-x-cache-on, akamai-x-cache-remote-on, akamai-x-check-cacheable, akamai-x-get-cache-key, akamai-x-get-extracted-values, akamai-x-get-nonces, akamai-x-get-ssl-client-session-id, akamai-x-get-true-cache-key, akamai-x-serial-no'
|
12
|
+
}
|
13
|
+
@expected_response_headers =
|
14
|
+
{
|
15
|
+
'x-cache' => /TCP(.*)HIT(.*)from(.*)AkamaiGHost(.*)/
|
16
|
+
}
|
17
|
+
@failures = {}
|
18
|
+
@response_headers = {}
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_response_headers headers
|
22
|
+
headers.each_header do |attr, value|
|
23
|
+
@response_headers[attr] = value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def fetch uri=@uri, headers=@headers
|
28
|
+
@url = uri
|
29
|
+
@headers= headers
|
30
|
+
set_response_headers(get_uri(uri, headers).header)
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def is_cached?
|
35
|
+
@response_headers.each do |attr, value|
|
36
|
+
@failures[attr] = "Expected= #{@expected_response_headers[attr]}, Actual= #{value}" unless @expected_response_headers[attr].nil? || value.match(@expected_response_headers[attr])
|
37
|
+
end
|
38
|
+
return ((@failures.empty?) ? true : false)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
GEM_VERSION = '0.0.1'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
class WebService
|
4
|
+
attr_accessor :headers,:uri
|
5
|
+
|
6
|
+
def service_request(host, port, request, use_ssl=false)
|
7
|
+
begin
|
8
|
+
http = Net::HTTP.new(host, port)
|
9
|
+
if use_ssl
|
10
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
11
|
+
http.use_ssl = true
|
12
|
+
end
|
13
|
+
http.start { |htttp| htttp.request(request) }
|
14
|
+
rescue Exception => ex
|
15
|
+
raise "Unable to fetch #{@uri.request_uri}. Check if site is up and running"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def get(host, port, endpoint, headers)
|
20
|
+
request = Net::HTTP::Get.new(endpoint, headers)
|
21
|
+
response = service_request(host, port, request)
|
22
|
+
response
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_uri uri, headers
|
26
|
+
@uri = URI.parse(uri)
|
27
|
+
get(@uri.host, @uri.port, @uri.path, headers)
|
28
|
+
end
|
29
|
+
end
|
data/test/test_helper.rb
ADDED
data/thanks.txt
ADDED
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cachewarp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- codeweft
|
9
|
+
- bitweft
|
10
|
+
- juteroot
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2013-06-17 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: bundler
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '1.3'
|
24
|
+
type: :development
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ~>
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '1.3'
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: rake
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
description: Gem to verify cache and content delivery headers
|
49
|
+
email:
|
50
|
+
- juteroot@gmail.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- cachewarp.gemspec
|
61
|
+
- lib/cachewarp.rb
|
62
|
+
- lib/cachewarp/version.rb
|
63
|
+
- lib/cachewarp/web_service.rb
|
64
|
+
- test/lib/cachewarp/akamai_test.rb
|
65
|
+
- test/lib/cachewarp/version_test.rb
|
66
|
+
- test/test_helper.rb
|
67
|
+
- thanks.txt
|
68
|
+
homepage: http://www.juteroot.com
|
69
|
+
licenses:
|
70
|
+
- To be decided
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
hash: 138774292347802239
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
hash: 138774292347802239
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 1.8.25
|
96
|
+
signing_key:
|
97
|
+
specification_version: 3
|
98
|
+
summary: Gem to verify cache and content delivery headers
|
99
|
+
test_files:
|
100
|
+
- test/lib/cachewarp/akamai_test.rb
|
101
|
+
- test/lib/cachewarp/version_test.rb
|
102
|
+
- test/test_helper.rb
|