rails_response_headers 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 41f72d60f9a51cd28ccb3052db35d716e32b9ad9
4
+ data.tar.gz: 61a5d98218975f0732b550674b7badac427b449b
5
+ SHA512:
6
+ metadata.gz: 29528a4c232ff44d5ec64e4317841523fcdc81243002fedff0079899a0b6b531a7a6c5cc6dd143e4526b3015d4d41c4d7eb09d49df85926a68e4a20c40e015c1
7
+ data.tar.gz: d045ff0828d01bce503a3015b328c0502be28c3388e0782a556a5048b391f11f93eb8ad49e14bb8a4b84417c68326625c3616349adeeec6992dc5e63cffdc1b1
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails_response_headers.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Peter Woo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # RailsResponseHeaders
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'rails_response_headers'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ ## Usage
16
+
17
+ Create a YAML file at `config/response-headers.yml` with a mapping from your controller actions
18
+ to the set of headers which should be set in the response. For example:
19
+
20
+ ```
21
+ # config/response-headers.yml
22
+
23
+ welcome#index:
24
+ Surrogate-Control: public, max-age=120
25
+ Vary: Accept-Encoding, Accept-Language
26
+ ```
27
+
28
+ When the `index` action of `WelcomeController` is hit, `Surrogate-Control` and `Vary` headers will
29
+ be included in the response.
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/efforg/rails_response_headers.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
38
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rails_response_headers"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require "rails_response_headers/version"
2
+ require "rails_response_headers/railtie" if defined?(Rails)
3
+
4
+ module RailsResponseHeaders
5
+ end
@@ -0,0 +1,34 @@
1
+ module RailsResponseHeaders
2
+ module Filter
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ cattr_accessor :rails_response_headers
7
+
8
+ before_filter :set_rails_response_headers
9
+ end
10
+
11
+ class_methods do
12
+ def load_rails_response_headers
13
+ config_file = Rails.application.config.response_headers.config
14
+
15
+ if File.exists?(config_file)
16
+ self.rails_response_headers = YAML.load_file(config_file)
17
+ else
18
+ self.rails_response_headers = {}
19
+ end
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def set_rails_response_headers
26
+ controller_map = rails_response_headers[controller_name] || {}
27
+ action_headers = controller_map[action_name] || {}
28
+
29
+ action_headers.each do |name, value|
30
+ response.headers[name] ||= value
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,21 @@
1
+ require "rails_response_headers/filter"
2
+
3
+ module RailsResponseHeaders
4
+ class Railtie < Rails::Railtie
5
+ config.response_headers = ActiveSupport::OrderedOptions.new
6
+
7
+ initializer "rails_response_headers.extend_action_controller" do
8
+ ActiveSupport.on_load(:action_controller) do
9
+ ActionController::Base.send(:include, RailsResponseHeaders::Filter)
10
+ end
11
+ end
12
+
13
+ initializer "rails_response_headers.configure" do
14
+ config.response_headers.config ||= Rails.root.join("config/response-headers.yml")
15
+ end
16
+
17
+ config.to_prepare do
18
+ ActionController::Base.load_rails_response_headers
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module RailsResponseHeaders
2
+ VERSION = "0.1.0"
3
+ end
@@ -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 'rails_response_headers/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails_response_headers"
8
+ spec.version = RailsResponseHeaders::VERSION
9
+ spec.authors = ["Peter Woo"]
10
+ spec.email = ["peterw@eff.org"]
11
+
12
+ spec.summary = %q{Configure ActionController response headers with YAML.}
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.12"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec", "~> 3.0"
23
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_response_headers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Peter Woo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - peterw@eff.org
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/rails_response_headers.rb
72
+ - lib/rails_response_headers/filter.rb
73
+ - lib/rails_response_headers/railtie.rb
74
+ - lib/rails_response_headers/version.rb
75
+ - rails_response_headers.gemspec
76
+ homepage:
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.5.1
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Configure ActionController response headers with YAML.
100
+ test_files: []