rack-merge-cookies 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0fd3ebdefe00156efe2eb9b227a79f0949ec5aa4
4
+ data.tar.gz: 88011839a4077331f0ccebf96d2c2de98f030be9
5
+ SHA512:
6
+ metadata.gz: cf1fc52091526c4cd018abea69818b2ac74c58ce9d447c4f5869fb646a88abec87bd71164f3cceceab4aef922d6c82d4549bb80b0f9c759fe3fa487026a72d45
7
+ data.tar.gz: 607665e817dbc7705f6006efc0c9a8ed1a726c42dec8af39299f593e8c5ed27fde76385b000594acaefd02b09e6bf2f52b214df43d652cbb0cf5f7ad6342a2bf
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1 @@
1
+ ruby-2.2.2
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.1
6
+ notifications:
7
+ email: false
8
+ env:
9
+ - "rack=1.2.8"
10
+ - "rack=1.3.10"
11
+ - "rack=1.4.5"
12
+ - "rack=1.5.2"
13
+ - "rack=master"
data/Gemfile ADDED
@@ -0,0 +1,22 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rake'
6
+
7
+ github = 'git://github.com/%s.git'
8
+ repos = { 'rack' => github % 'rack/rack' }
9
+
10
+ %w(rack).each do |lib|
11
+ dep = case ENV[lib]
12
+ when 'stable', nil then nil
13
+ when /(\d+\.)+\d+/ then '~> ' + ENV[lib].sub("#{lib}-", '')
14
+ else { git: repos[lib], branch: dep }
15
+ end
16
+ gem lib, dep
17
+ end
18
+
19
+ group :test do
20
+ gem 'rack-test'
21
+ gem 'coveralls', require: false
22
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Shogo Iwano
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.
@@ -0,0 +1,50 @@
1
+ # Rack::MergeCookies [![Build Status](https://secure.travis-ci.org/shiwano/rack-merge-cookies.png)](https://travis-ci.org/shiwano/rack-merge-cookies?branch=master)
2
+
3
+ Rack middleware to merge the user-defined header to cookies.
4
+
5
+ Example:
6
+
7
+ ```
8
+ Cookie: foo=1; bar=2
9
+ X-Cookie: baz=3
10
+ ```
11
+
12
+ This headers will be merged like this below.
13
+
14
+ ```
15
+ Cookie: foo=1; bar=2; baz=3
16
+ ```
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ gem 'rack-merge-cookies'
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install rack-merge-cookies
31
+
32
+ ## Ruby on Rails
33
+
34
+ To make the middleware available in all environments, open `config/application.rb` and add in `class Application < Rails::Application`:
35
+
36
+ ```ruby
37
+ config.middleware.insert_before(ActionDispatch::Cookies, Rack::MergeCookies, header_name: 'X-COOKIE')
38
+ ```
39
+
40
+ If you want to customize the environment in which the middleware is enabled edit the respective environment files instead.
41
+
42
+ You can verify the middleware positioning by typing `rake middleware` in the root of your application.
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rake/testtask"
4
+ Rake::TestTask.new do |t|
5
+ t.libs.push "lib"
6
+ t.test_files = FileList['spec/*_spec.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1 @@
1
+ require 'rack/merge-cookies'
@@ -0,0 +1,20 @@
1
+ module Rack
2
+ class MergeCookies
3
+ def initialize(app, options = {})
4
+ @app, @header_name = app, options[:header_name]
5
+ end
6
+
7
+ def custom_cookie_name
8
+ 'HTTP_' + @header_name.upcase.gsub('-', '_')
9
+ end
10
+
11
+ def call(env)
12
+ custom_cookie = env[custom_cookie_name]
13
+ unless custom_cookie.nil?
14
+ cookie = (env['HTTP_COOKIE'] || '').gsub(/;$/, '')
15
+ env['HTTP_COOKIE'] = cookie + '; ' + custom_cookie
16
+ end
17
+ @app.call(env)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class MergeCookies
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rack/merge-cookies/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rack-merge-cookies'
8
+ spec.version = Rack::MergeCookies::VERSION
9
+ spec.authors = ['Shogo Iwano']
10
+ spec.email = ['shiwano@gmail.com']
11
+ spec.summary = 'Rack middleware to merge the user-defined header to cookies.'
12
+ spec.description = 'Rack middleware to merge the user-defined header to cookies.'
13
+ spec.homepage = 'http://github.com/shiwano/rack-merge-cookies'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
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.0'
22
+ spec.add_development_dependency 'rack', '~> 1.2'
23
+ spec.add_development_dependency 'rack-test', '~> 0.6.2'
24
+ end
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'minitest/spec'
3
+ require 'minitest/autorun'
4
+ require 'rack/mock'
5
+ require 'rack/test'
6
+ require 'coveralls'
7
+
8
+ require_relative '../lib/rack/merge-cookies'
9
+
10
+ Coveralls.wear!
11
+
12
+ describe Rack::MergeCookies do
13
+ include Rack::Test::Methods
14
+
15
+ def app; Rack::Lint.new(@app); end
16
+
17
+ def mock_app(options_or_options_array = {})
18
+ main_app = lambda { |env|
19
+ headers = {'Content-Type' => "text/html"}
20
+ [200, headers, ['Hello there']]
21
+ }
22
+
23
+ builder = Rack::Builder.new
24
+ options_or_options_array = [options_or_options_array] unless options_or_options_array.is_a?(Array)
25
+ Array(options_or_options_array).each do |options|
26
+ builder.use Rack::MergeCookies, options
27
+ end
28
+ builder.run main_app
29
+ @app = builder.to_app
30
+ end
31
+
32
+ before do
33
+ mock_app([header_name: 'X-COOKIE'])
34
+ end
35
+
36
+ it 'should merge the user-defined header to cookies' do
37
+ header 'COOKIE', 'foo=1; bar=2;'
38
+ header 'X-COOKIE', 'baz=3;'
39
+ get 'http://www.example.org'
40
+ last_request.env['HTTP_COOKIE'].must_equal('foo=1; bar=2; baz=3;')
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-merge-cookies
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Shogo Iwano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-11 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.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack-test
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.6.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.6.2
55
+ description: Rack middleware to merge the user-defined header to cookies.
56
+ email:
57
+ - shiwano@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".ruby-version"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - lib/rack-merge-cookies.rb
71
+ - lib/rack/merge-cookies.rb
72
+ - lib/rack/merge-cookies/version.rb
73
+ - rack-merge-cookies.gemspec
74
+ - spec/rack-merge-cookies_spec.rb
75
+ homepage: http://github.com/shiwano/rack-merge-cookies
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.5
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Rack middleware to merge the user-defined header to cookies.
99
+ test_files:
100
+ - spec/rack-merge-cookies_spec.rb