rack-vendor_accept_header 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +15 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +110 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/rack/vendor_accept_header.rb +30 -0
- data/lib/rack/vendor_accept_header/version.rb +5 -0
- data/rack-vendor_accept_header.gemspec +27 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9c91d3f2be51f0a1f1ddf59f1d8950c59bc51e4a
|
4
|
+
data.tar.gz: 044ec15f4ae9ce158dc685464f0bb5777d837962
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 74d4417e73594ed204f9a9f7f1b6ef79a12c81477fa04c8e3c21874755ae2da7a7d2f20e59b91a8d6f5ece538db654d8e9a2a5afc0c9061f2758d2384cf0e5d4
|
7
|
+
data.tar.gz: 333578848e3e4bd9b4187126bc19f0964b72c2bde76c7ed37e7a058089db0bb9aa8a4c69127e24710e1a2178955368d3cff07beb54c0e5f89a268659e31d4744
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# ChangeLog
|
2
|
+
|
3
|
+
The following are lists of the notable changes included with each release.
|
4
|
+
This is intended to help keep people informed about notable changes between
|
5
|
+
versions as well as provide a rough history.
|
6
|
+
|
7
|
+
#### Next Release
|
8
|
+
|
9
|
+
#### v1.0.0
|
10
|
+
|
11
|
+
* wrote READEME.md
|
12
|
+
* added vnd version parsing & exposure
|
13
|
+
* added vnd context parsing & exposure
|
14
|
+
* added vnd type parsing & exposure
|
15
|
+
* added vnd sub_type parsing & exposure
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Andrew De Ponte
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
# Rack::VendorAcceptHeader
|
2
|
+
|
3
|
+
Welcome to the `rack-vendor_accept_header` gem. It provides
|
4
|
+
[rack](http://rack.github.io) middleware that parses [vendor based mime
|
5
|
+
types](https://tools.ietf.org/html/rfc4288#section-3.2) in the HTTP
|
6
|
+
Accept header.
|
7
|
+
|
8
|
+
```http
|
9
|
+
GET /something HTTP/1.1
|
10
|
+
Accept: application/vnd.acme.v3+json
|
11
|
+
```
|
12
|
+
|
13
|
+
The primary impetus for doing this is to be able to use vendor mime
|
14
|
+
types in the HTTP Accept header for REST API versioning as well as for
|
15
|
+
content negotiation. The [GitHub API's usage of Media
|
16
|
+
Types](https://developer.github.com/v3/media/) is an excellent example
|
17
|
+
of this.
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
Add this line to your application's Gemfile:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem 'rack-vendor_accept_header'
|
25
|
+
```
|
26
|
+
|
27
|
+
And then execute:
|
28
|
+
|
29
|
+
$ bundle
|
30
|
+
|
31
|
+
Or install it yourself as:
|
32
|
+
|
33
|
+
$ gem install rack-vendor_accept_header
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
Given that this is [rack](http://rack.github.io) middleware, it can be
|
38
|
+
used with pure [rack](http://rack.github.io) applications, or with the
|
39
|
+
vast number of web frameworks that are built on top of
|
40
|
+
[rack](http://rack.github.io). This includes [Ruby on
|
41
|
+
Rails](http://rubyonrails.org), [Sinatra](http://www.sinatrarb.com),
|
42
|
+
[Grape](http://intridea.github.io/grape/), etc. Details on using
|
43
|
+
[rack](http://rack.github.io) middleware within each of these framework
|
44
|
+
can be found within their respective documentation. However, the
|
45
|
+
following is a quick example of how you would register this
|
46
|
+
[rack](http://rack.github.io) middleware in
|
47
|
+
[Sinatra](http://www.sinatrarb.com).
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
use Rack::VendorAcceptHeader
|
51
|
+
```
|
52
|
+
|
53
|
+
When you use this middleware it parses and exposes the `type`, `sub_type`,
|
54
|
+
`context`, and `version` out of the vendor based mime type HTTP Accept
|
55
|
+
header.
|
56
|
+
|
57
|
+
```http
|
58
|
+
GET /something HTTP/1.1
|
59
|
+
Accept: application/vnd.acme.v3+json
|
60
|
+
```
|
61
|
+
|
62
|
+
Given the example above this middleware would expose these components in
|
63
|
+
the [rack](http://rack.github.io) env as follows:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
request.env['vnd_type'] # => 'application'
|
67
|
+
request.env['vnd_sub_type'] # => 'json'
|
68
|
+
request.env['vnd_version'] # => '3'
|
69
|
+
request.env['vnd_context'] # => 'acme'
|
70
|
+
```
|
71
|
+
|
72
|
+
## References
|
73
|
+
|
74
|
+
If you are interested in any of the references around this use case and
|
75
|
+
the details around it. Please see the following.
|
76
|
+
|
77
|
+
- [GitHub API Media Types](https://developer.github.com/v3/media/)
|
78
|
+
- [rfc2616 sec14 - Header Field Definitions](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html)
|
79
|
+
- [rfc4288 sec3.2 - Media Type Specifications and Registration Procedures](https://tools.ietf.org/html/rfc4288#section-3.2)
|
80
|
+
- [Using the Accept Header to version your API](http://labs.qandidate.com/blog/2014/10/16/using-the-accept-header-to-version-your-api/)
|
81
|
+
- [Pivotal Labs - API Versioning](https://blog.pivotal.io/labs/labs/api-versioning)
|
82
|
+
- [Nobody Understands REST or HTTP](http://blog.steveklabnik.com/posts/2011-07-03-nobody-understands-rest-or-http)
|
83
|
+
- [MIMETYPES (AND APIS)](https://daveyshafik.com/archives/35507-mimetypes-and-apis.html)
|
84
|
+
- [Versioning REST Web Services](http://barelyenough.org/blog/2008/05/versioning-rest-web-services/)
|
85
|
+
|
86
|
+
## Development
|
87
|
+
|
88
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
89
|
+
Then, run `rake spec` to run the tests. You can also run `bin/console`
|
90
|
+
for an interactive prompt that will allow you to experiment.
|
91
|
+
|
92
|
+
To install this gem onto your local machine, run `bundle exec rake
|
93
|
+
install`. To release a new version, update the version number in
|
94
|
+
`version.rb`, and then run `bundle exec rake release`, which will create
|
95
|
+
a git tag for the version, push git commits and tags, and push the
|
96
|
+
`.gem` file to [rubygems.org](https://rubygems.org).
|
97
|
+
|
98
|
+
## Contributing
|
99
|
+
|
100
|
+
Bug reports and pull requests are welcome on GitHub at
|
101
|
+
[https://github.com/codebreakdown/rack-vendor_accept_header](https://github.com/codebreakdown/rack-vendor_accept_header).
|
102
|
+
This project is intended to be a safe, welcoming space for
|
103
|
+
collaboration, and contributors are expected to adhere to the
|
104
|
+
[Contributor Covenant](contributor-covenant.org) code of conduct.
|
105
|
+
|
106
|
+
## License
|
107
|
+
|
108
|
+
The gem is available as open source under the terms of the [MIT
|
109
|
+
License](http://opensource.org/licenses/MIT).
|
110
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rack/vendor_accept_header"
|
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
|
data/bin/setup
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "rack/vendor_accept_header/version"
|
2
|
+
require "rack"
|
3
|
+
|
4
|
+
module Rack
|
5
|
+
class VendorAcceptHeader
|
6
|
+
def initialize(app, options = {})
|
7
|
+
@app = app
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
parts = parse_accept_header(env)
|
13
|
+
env['vnd_version'] = parts[:version]
|
14
|
+
env['vnd_context'] = parts[:context]
|
15
|
+
env['vnd_type'] = parts[:type]
|
16
|
+
env['vnd_sub_type'] = parts[:sub_type]
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def parse_accept_header(env)
|
23
|
+
if env['HTTP_ACCEPT'] =~ /application\/vnd\.(\w+)\.v(\d+(?:\.\d+)*)\+(\w+)/
|
24
|
+
return { type: 'application', context: $1, version: $2, sub_type: $3 }
|
25
|
+
else
|
26
|
+
return { type: nil, context: nil, version: nil, sub_type: nil }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack/vendor_accept_header/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rack-vendor_accept_header"
|
8
|
+
spec.version = Rack::VendorAcceptHeader::VERSION
|
9
|
+
spec.authors = ["Andrew De Ponte"]
|
10
|
+
spec.email = ["cyphactor@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Rack middleware to parse vendor accept headers}
|
13
|
+
spec.description = %q{Rack middleware to aid with parsing vendor accept headers}
|
14
|
+
spec.homepage = "https://github.com/codebreakdown/rack-vendor_accept_header"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "rack", "~> 1.6"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
26
|
+
spec.add_development_dependency "rack-test", "~> 0.6"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-vendor_accept_header
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew De Ponte
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack-test
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.6'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.6'
|
83
|
+
description: Rack middleware to aid with parsing vendor accept headers
|
84
|
+
email:
|
85
|
+
- cyphactor@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- CHANGELOG.md
|
94
|
+
- CODE_OF_CONDUCT.md
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- lib/rack/vendor_accept_header.rb
|
102
|
+
- lib/rack/vendor_accept_header/version.rb
|
103
|
+
- rack-vendor_accept_header.gemspec
|
104
|
+
homepage: https://github.com/codebreakdown/rack-vendor_accept_header
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.4.5.1
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Rack middleware to parse vendor accept headers
|
128
|
+
test_files: []
|