rack-headercontrol 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +22 -0
- data/Rakefile +1 -0
- data/lib/rack-headercontrol/version.rb +5 -0
- data/lib/rack-headercontrol.rb +43 -0
- data/rack-headercontrol.gemspec +23 -0
- metadata +87 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#Rack::HeaderControl
|
2
|
+
|
3
|
+
Rack Middleware that allows you set/override response headers for selected paths
|
4
|
+
|
5
|
+
If you want to set headers for all responses, have a look at
|
6
|
+
Rack::ResponseHeaders from rack-contrib
|
7
|
+
|
8
|
+
Conditions can be set using strings or regexes. It will execute the passed
|
9
|
+
block for every condition that matches
|
10
|
+
|
11
|
+
##Usage
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
use Rack::HeaderControl do |change|
|
15
|
+
change.path '/tralala' do |headers|
|
16
|
+
headers['X-Foo'] = 'bar'
|
17
|
+
end
|
18
|
+
change.path /./ do |headers|
|
19
|
+
headers.delete('X-Baz')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "rack-headercontrol/version"
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
class HeaderControl
|
5
|
+
def initialize(app, &config_block)
|
6
|
+
@app = app
|
7
|
+
@config_block = config_block
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
@app.call(env).tap do |response|
|
12
|
+
@recorder = PathRecorder.new
|
13
|
+
@config_block.call(@recorder)
|
14
|
+
request = Rack::Request.new(env)
|
15
|
+
response_headers = Utils::HeaderHash.new(response[1])
|
16
|
+
@recorder.each do |condition, action|
|
17
|
+
if request.path.match condition
|
18
|
+
action.call(response_headers)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
response[1] = response_headers
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class PathRecorder
|
27
|
+
def initialize
|
28
|
+
@paths = {}
|
29
|
+
end
|
30
|
+
|
31
|
+
def path(path, &block)
|
32
|
+
@paths[path] = block
|
33
|
+
end
|
34
|
+
|
35
|
+
def [](path)
|
36
|
+
@paths[path]
|
37
|
+
end
|
38
|
+
|
39
|
+
def each(&block)
|
40
|
+
@paths.each(&block)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rack-headercontrol/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rack-headercontrol"
|
7
|
+
s.version = Rack::Headercontrol::VERSION
|
8
|
+
s.authors = ["Gerrit Kaiser"]
|
9
|
+
s.email = ["gerrit@gerritkaiser.de"]
|
10
|
+
s.homepage = 'http://github.com/gerrit/rack-headercontrol'
|
11
|
+
s.summary = 'Rack Middleware that allows you set/override response headers for selected paths'
|
12
|
+
s.description = ''
|
13
|
+
|
14
|
+
s.rubyforge_project = 'rack-headercontrol'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# s.add_development_dependency "rspec"
|
22
|
+
s.add_runtime_dependency 'rack'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-headercontrol
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Gerrit Kaiser
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-11-10 00:00:00 +00:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rack
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: ""
|
36
|
+
email:
|
37
|
+
- gerrit@gerritkaiser.de
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- Gemfile
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- lib/rack-headercontrol.rb
|
50
|
+
- lib/rack-headercontrol/version.rb
|
51
|
+
- rack-headercontrol.gemspec
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://github.com/gerrit/rack-headercontrol
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 3
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project: rack-headercontrol
|
82
|
+
rubygems_version: 1.4.2
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Rack Middleware that allows you set/override response headers for selected paths
|
86
|
+
test_files: []
|
87
|
+
|