cloudseed 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +7 -0
  2. data/lib/cloudseed.rb +51 -0
  3. metadata +79 -0
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "rake/testtask"
2
+
3
+ task :default => :test
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.warning = true
7
+ end
data/lib/cloudseed.rb ADDED
@@ -0,0 +1,51 @@
1
+ module CloudSeed
2
+ class Middleware
3
+ COMPRESSABLE = ["javascript", "json", "atom+xml", "xml", "pdf"].map do |f|
4
+ "application/#{f}"
5
+ end
6
+ attr_accessor :app
7
+
8
+ def initialize(app)
9
+ self.app = app
10
+ end
11
+
12
+ def call(env)
13
+ munge_version(env)
14
+
15
+ status, headers, body = app.call(env)
16
+
17
+ if is_compressable?(headers['Content-Type'])
18
+ headers['Vary'] = 'Accept-Encoding'
19
+ end
20
+
21
+ [status, headers, body]
22
+ end
23
+
24
+ def is_compressable?(mime)
25
+ return mime.start_with?('text/') ||
26
+ COMPRESSABLE.any?{|c| mime.start_with?(c) }
27
+ end
28
+
29
+ def munge_version(env)
30
+ if (v = extract_version(env['PATH_INFO']))
31
+ env['PATH_INFO'] = v.first
32
+
33
+ qs = env['QUERY_STRING']
34
+ if qs.nil? || qs.strip == ''
35
+ qs = v[1]
36
+ else
37
+ qs = "&#{v[1]}"
38
+ end
39
+ env['QUERY_STRING'] = qs
40
+ end
41
+ end
42
+
43
+ def extract_version(path)
44
+ if path =~ /(.+)\.v(\w+)(\.\w+)?$/
45
+ [$1 + $3, $2]
46
+ else
47
+ nil
48
+ end
49
+ end
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloudseed
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Kurt Mackey
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-02-13 00:00:00 -06:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rack
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 0
31
+ - 0
32
+ version: 1.0.0
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: CloudSeed is a Rack-based utility to manage backend delivery of CloudFront custom origins.
36
+ email: mrkurt@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - Rakefile
45
+ - lib/cloudseed.rb
46
+ has_rdoc: true
47
+ homepage: http://github.com/mrkurt/cloudseed/
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options: []
52
+
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ requirements: []
72
+
73
+ rubyforge_project:
74
+ rubygems_version: 1.3.7
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Rack-based helper for CloudFront custom origins
78
+ test_files: []
79
+