rack-cookie_rewrite 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
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
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-cookie_rewrite.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Tom Chipchase
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,48 @@
1
+ # Rack::CookieRewrite
2
+
3
+ This is a Rack middleware to add extra headers which behave like the Cookie and
4
+ Set-Cookie headers.
5
+
6
+ This simple middleware sets anything in the X-#{prefix}-Cookie header to
7
+ Cookie, and in the response will copy anything in Set-Cookie to
8
+ X-#{prefix}-Set-Cookie. This can be useful to enable session management where
9
+ an HTML client is accessing your API, which doesn't fully support cookies. We
10
+ have found this to be the case in some Smart TV web applications, and in mobile
11
+ apps written using frameworks such as Cordova
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'rack-cookie_rewrite'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install rack-cookie_rewrite
26
+
27
+ ## Usage
28
+
29
+ In your config.ru, or where ever else you set up your Rack environment, add the
30
+ following lines:
31
+
32
+ require 'rack/cookie_rewrite'
33
+ use Rack::CookieRewrite, 'MSP'
34
+
35
+ Then use cookies in your Rack application as normal.
36
+
37
+ In your client application, you can then use X-MSP-Cookie and X-MSP-Set-Cookie
38
+ in lieu of normal Cookie commands. This means you will have to manually read
39
+ and set these headers if you are sending requests that expect and set cookies.
40
+
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it ( https://github.com/[my-github-username]/rack-cookie_rewrite/fork )
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+
3
+ module Rack
4
+ # Rack middleware to add an alternate header for Cookies.
5
+ class CookieRewrite
6
+ def initialize(app, prefix)
7
+ @app = app
8
+ @prefix = prefix
9
+ end
10
+
11
+ def call(env)
12
+ (cookie = env["HTTP_X_#{@prefix}_COOKIE"]) &&
13
+ (env['HTTP_COOKIE'] = cookie)
14
+
15
+ status, headers, body = @app.call(env)
16
+
17
+ (cookie = headers['Set-Cookie']) &&
18
+ headers["X-#{@prefix}-Set-Cookie"] = cookie
19
+
20
+ [status, headers, body]
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rack-cookie_rewrite'
8
+ spec.version = '1.0.0'
9
+ spec.authors = ['Tom Chipchase']
10
+ spec.email = ['tom@mediasp.com']
11
+
12
+ spec.summary = %q{Rack middleware to add extra headers which behave
13
+ like the Cookie and Set-Cookie headers}
14
+
15
+ spec.description = %q{This simple middleware sets anything in the
16
+ X-#{prefix}-Cookie header to Cookie, and in the response will copy anything in
17
+ Set-Cookie to X-#{prefix}-Set-Cookie. This can be useful to enable session
18
+ management where an HTML client is accessing your API, which doesn't fully
19
+ support cookies. We have found this to be the case in some Smart TV web
20
+ applications, and in mobile apps written using frameworks such as Cordova}
21
+
22
+ spec.homepage = 'https://github.com/mediasp/rack-cookie_rewrite.git'
23
+ spec.license = 'MIT'
24
+
25
+ spec.files = `git ls-files -z`.split("\x0")
26
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
27
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.6'
31
+ spec.add_development_dependency 'rake'
32
+ spec.add_development_dependency 'bump'
33
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-cookie_rewrite
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tom Chipchase
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-07-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.6'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bump
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: ! 'This simple middleware sets anything in the
63
+
64
+ X-#{prefix}-Cookie header to Cookie, and in the response will copy anything in
65
+
66
+ Set-Cookie to X-#{prefix}-Set-Cookie. This can be useful to enable session
67
+
68
+ management where an HTML client is accessing your API, which doesn''t fully
69
+
70
+ support cookies. We have found this to be the case in some Smart TV web
71
+
72
+ applications, and in mobile apps written using frameworks such as Cordova'
73
+ email:
74
+ - tom@mediasp.com
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - .gitignore
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - lib/rack/cookie_rewrite.rb
85
+ - rack-cookie_rewrite.gemspec
86
+ homepage: https://github.com/mediasp/rack-cookie_rewrite.git
87
+ licenses:
88
+ - MIT
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 1.8.23
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: Rack middleware to add extra headers which behave like the Cookie and Set-Cookie
111
+ headers
112
+ test_files: []