http-accept 2.1.1 → 2.2.0
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/.DS_Store +0 -0
- data/lib/http/accept/languages.rb +1 -1
- data/lib/http/accept/media_types.rb +4 -0
- data/lib/http/accept/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +48 -34
- metadata.gz.sig +0 -0
- data/.gitignore +0 -19
- data/.rspec +0 -3
- data/.travis.yml +0 -21
- data/Gemfile +0 -4
- data/README.md +0 -137
- data/Rakefile +0 -6
- data/http-accept.gemspec +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df0246f182c9234cb68ea3049b0db11f86c503bfc53a7e72fa4f7ecc13da7151
|
4
|
+
data.tar.gz: a07dea0b41e4c7a0962e8be0543e7f714b7d1a20cf820cd413d90acaf0a1a0e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b030b40a094e4b46726aa5e20a4c1b89b332218c165d2b1667159528229446b45cdc34c624acc7a90aed4cdd4dae663d125e61697825739b61abb01f255d4b5
|
7
|
+
data.tar.gz: cdcd43429064dd0510cd6333a76f707e9fae42f5388316e5a977bfe34caf24c0ff047ffb08cdbcdb109d553b844857d55b765b48cbde60058ea57d8170762ac1
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data/lib/.DS_Store
ADDED
Binary file
|
@@ -32,7 +32,7 @@ module HTTP
|
|
32
32
|
LOCALE = /\*|[A-Z]{1,8}(-[A-Z0-9]{1,8})*/i
|
33
33
|
|
34
34
|
# https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.9
|
35
|
-
QVALUE = /0(\.[0-9]{0,
|
35
|
+
QVALUE = /0(\.[0-9]{0,6})?|1(\.[0]{0,6})?/
|
36
36
|
|
37
37
|
# https://greenbytes.de/tech/webdav/rfc7231.html#quality.values
|
38
38
|
LANGUAGE_RANGE = /(?<locale>#{LOCALE})(\s*;\s*q=(?<q>#{QVALUE}))?/
|
@@ -38,6 +38,10 @@ module HTTP
|
|
38
38
|
|
39
39
|
# A single entry in the Accept: header, which includes a mime type and associated parameters.
|
40
40
|
MediaRange = Struct.new(:type, :subtype, :parameters) do
|
41
|
+
def initialize(type, subtype = '*', parameters = {})
|
42
|
+
super(type, subtype, parameters)
|
43
|
+
end
|
44
|
+
|
41
45
|
def parameters_string
|
42
46
|
return '' if parameters == nil or parameters.empty?
|
43
47
|
|
data/lib/http/accept/version.rb
CHANGED
data.tar.gz.sig
ADDED
Binary file
|
metadata
CHANGED
@@ -1,17 +1,51 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http-accept
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
- Matthew Kerwin
|
9
|
+
- Alif Rachmawadi
|
10
|
+
- Andy Brody
|
11
|
+
- Khaled Hassan Hussein
|
12
|
+
- Olle Jonsson
|
13
|
+
- Robert Pritzkow
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain:
|
17
|
+
- |
|
18
|
+
-----BEGIN CERTIFICATE-----
|
19
|
+
MIIEhDCCAuygAwIBAgIBATANBgkqhkiG9w0BAQsFADA3MTUwMwYDVQQDDCxzYW11
|
20
|
+
ZWwud2lsbGlhbXMvREM9b3Jpb250cmFuc2Zlci9EQz1jby9EQz1uejAeFw0yMTA4
|
21
|
+
MTYwNjMzNDRaFw0yMjA4MTYwNjMzNDRaMDcxNTAzBgNVBAMMLHNhbXVlbC53aWxs
|
22
|
+
aWF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QPFL/gSUc6aK
|
37
|
+
vszMHIyhtyzRc6DnfW2AiVOjMBjaYv8xXZc9bduniRVPrLR4J7ozmGLh4o4uJp7w
|
38
|
+
x9KCFaR8Lvn/r0oJWJOqb/DMAYI83YeN2Dlt3jpwrsmsONrtC5S3gOUle5afSGos
|
39
|
+
bYt5ocnEpKSomR9ZtnCGljds/aeO1Xgpn2r9HHcjwnH346iNrnHmMlC7BtHUFPDg
|
40
|
+
Ts92S47PTOXzwPBDsrFiq3VLbRjHSwf8rpqybQBH9MfzxGGxTaETQYOd6b4e4Ag6
|
41
|
+
y92abGna0bmIEb4+Tx9rQ10Uijh1POzvr/VTH4bbIPy9FbKrRsIQ24qDbNJRtOpE
|
42
|
+
RAOsIl+HOBTb252nx1kIRN5hqQx272AJCbCjKx8egcUQKffFVVCI0nye09v5CK+a
|
43
|
+
HiLJ8VOFx6w=
|
44
|
+
-----END CERTIFICATE-----
|
45
|
+
date: 2022-08-02 00:00:00.000000000 Z
|
12
46
|
dependencies:
|
13
47
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
48
|
+
name: bundler
|
15
49
|
requirement: !ruby/object:Gem::Requirement
|
16
50
|
requirements:
|
17
51
|
- - ">="
|
@@ -25,7 +59,7 @@ dependencies:
|
|
25
59
|
- !ruby/object:Gem::Version
|
26
60
|
version: '0'
|
27
61
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
62
|
+
name: covered
|
29
63
|
requirement: !ruby/object:Gem::Requirement
|
30
64
|
requirements:
|
31
65
|
- - ">="
|
@@ -38,20 +72,6 @@ dependencies:
|
|
38
72
|
- - ">="
|
39
73
|
- !ruby/object:Gem::Version
|
40
74
|
version: '0'
|
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
75
|
- !ruby/object:Gem::Dependency
|
56
76
|
name: rspec
|
57
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,20 +86,13 @@ dependencies:
|
|
66
86
|
- - "~>"
|
67
87
|
- !ruby/object:Gem::Version
|
68
88
|
version: '3.0'
|
69
|
-
description:
|
89
|
+
description:
|
70
90
|
email:
|
71
|
-
- samuel.williams@oriontransfer.co.nz
|
72
91
|
executables: []
|
73
92
|
extensions: []
|
74
93
|
extra_rdoc_files: []
|
75
94
|
files:
|
76
|
-
-
|
77
|
-
- ".rspec"
|
78
|
-
- ".travis.yml"
|
79
|
-
- Gemfile
|
80
|
-
- README.md
|
81
|
-
- Rakefile
|
82
|
-
- http-accept.gemspec
|
95
|
+
- lib/.DS_Store
|
83
96
|
- lib/http/accept.rb
|
84
97
|
- lib/http/accept/charsets.rb
|
85
98
|
- lib/http/accept/content_type.rb
|
@@ -94,8 +107,9 @@ files:
|
|
94
107
|
homepage: https://github.com/ioquatix/http-accept
|
95
108
|
licenses:
|
96
109
|
- MIT
|
97
|
-
metadata:
|
98
|
-
|
110
|
+
metadata:
|
111
|
+
funding_uri: https://github.com/sponsors/ioquatix/
|
112
|
+
post_install_message:
|
99
113
|
rdoc_options: []
|
100
114
|
require_paths:
|
101
115
|
- lib
|
@@ -110,8 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
124
|
- !ruby/object:Gem::Version
|
111
125
|
version: '0'
|
112
126
|
requirements: []
|
113
|
-
rubygems_version: 3.
|
114
|
-
signing_key:
|
127
|
+
rubygems_version: 3.3.7
|
128
|
+
signing_key:
|
115
129
|
specification_version: 4
|
116
130
|
summary: Parse Accept and Accept-Language HTTP headers.
|
117
131
|
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
sudo: required
|
3
|
-
dist: xenial
|
4
|
-
cache: bundler
|
5
|
-
|
6
|
-
matrix:
|
7
|
-
include:
|
8
|
-
- rvm: 2.3
|
9
|
-
- rvm: 2.4
|
10
|
-
- rvm: 2.5
|
11
|
-
- rvm: 2.6
|
12
|
-
- rvm: 2.6
|
13
|
-
env: COVERAGE=PartialSummary,Coveralls
|
14
|
-
- rvm: truffleruby
|
15
|
-
- rvm: jruby-head
|
16
|
-
env: JRUBY_OPTS="--debug -X+O"
|
17
|
-
- rvm: ruby-head
|
18
|
-
allow_failures:
|
19
|
-
- rvm: truffleruby
|
20
|
-
- rvm: ruby-head
|
21
|
-
- rvm: jruby-head
|
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,137 +0,0 @@
|
|
1
|
-
# HTTP::Accept
|
2
|
-
|
3
|
-
Provides a robust set of parsers for dealing with HTTP `Accept`, `Accept-Language`, `Accept-Encoding`, `Accept-Charset` headers.
|
4
|
-
|
5
|
-
[](http://travis-ci.org/socketry/http-accept)
|
6
|
-
[](https://codeclimate.com/github/socketry/http-accept)
|
7
|
-
[](https://coveralls.io/r/socketry/http-accept)
|
8
|
-
|
9
|
-
## Motivation
|
10
|
-
|
11
|
-
I've been [developing some tools for building RESTful endpoints](https://github.com/ioquatix/utopia/blob/master/lib/utopia/controller/respond.rb) and part of that involved versioning. After reviewing the options, I settled on using the `Accept: application/json;version=1` method [as outlined here](http://labs.qandidate.com/blog/2014/10/16/using-the-accept-header-to-version-your-api/).
|
12
|
-
|
13
|
-
The `version=1` part of the `media-type` is a `parameter` as defined by [RFC7231 Section 3.1.1.1](https://tools.ietf.org/html/rfc7231#section-3.1.1.1). After reviewing several existing different options for parsing the `Accept:` header, I noticed a disturbing trend: `header.split(',')`. Because parameters may contain quoted strings which contain commas, this is clearly not an appropriate way to parse the header.
|
14
|
-
|
15
|
-
I am concerned about correctness, security and performance. As such, I implemented this gem to provide a simple high level interface for both parsing and correctly interpreting these headers.
|
16
|
-
|
17
|
-
## Installation
|
18
|
-
|
19
|
-
Add this line to your application's Gemfile:
|
20
|
-
|
21
|
-
```ruby
|
22
|
-
gem 'http-accept'
|
23
|
-
```
|
24
|
-
|
25
|
-
And then execute:
|
26
|
-
|
27
|
-
$ bundle
|
28
|
-
|
29
|
-
Or install it yourself as:
|
30
|
-
|
31
|
-
$ gem install http-accept
|
32
|
-
|
33
|
-
## Usage
|
34
|
-
|
35
|
-
Here are some examples of how to parse various headers.
|
36
|
-
|
37
|
-
### Parsing Accept: headers
|
38
|
-
|
39
|
-
You can parse the incoming `Accept:` header:
|
40
|
-
|
41
|
-
```ruby
|
42
|
-
media_types = HTTP::Accept::MediaTypes.parse("text/html;q=0.5, application/json; version=1")
|
43
|
-
|
44
|
-
expect(media_types[0].mime_type).to be == "application/json"
|
45
|
-
expect(media_types[0].parameters).to be == {'version' => '1'}
|
46
|
-
expect(media_types[1].mime_type).to be == "text/html"
|
47
|
-
expect(media_types[1].parameters).to be == {'q' => '0.5'}
|
48
|
-
```
|
49
|
-
|
50
|
-
Normally, you'd want to match the media types against some set of available mime types:
|
51
|
-
|
52
|
-
```ruby
|
53
|
-
module ToJSON
|
54
|
-
def content_type
|
55
|
-
HTTP::Accept::ContentType.new("application", "json", charset: 'utf-8')
|
56
|
-
end
|
57
|
-
|
58
|
-
# Used for inserting into map.
|
59
|
-
def split(*args)
|
60
|
-
content_type.split(*args)
|
61
|
-
end
|
62
|
-
|
63
|
-
def convert(object, options)
|
64
|
-
object.to_json
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
module ToXML
|
69
|
-
# Are you kidding?
|
70
|
-
end
|
71
|
-
|
72
|
-
map = HTTP::Accept::MediaTypes::Map.new
|
73
|
-
map << ToJSON
|
74
|
-
map << ToXML
|
75
|
-
|
76
|
-
object, media_range = map.for(media_types)
|
77
|
-
content = object.convert(model, media_range.parameters)
|
78
|
-
response = [200, {'Content-Type' => object.content_type}, [content]]
|
79
|
-
```
|
80
|
-
|
81
|
-
### Parsing Accept-Language: headers
|
82
|
-
|
83
|
-
You can parse the incoming `Accept-Language:` header:
|
84
|
-
|
85
|
-
```ruby
|
86
|
-
languages = HTTP::Accept::Languages.parse("da, en-gb;q=0.8, en;q=0.7")
|
87
|
-
|
88
|
-
expect(languages[0].locale).to be == "da"
|
89
|
-
expect(languages[1].locale).to be == "en-gb"
|
90
|
-
expect(languages[2].locale).to be == "en"
|
91
|
-
```
|
92
|
-
|
93
|
-
Normally, you'd want to match the languages against some set of available localizations:
|
94
|
-
|
95
|
-
```ruby
|
96
|
-
available_localizations = HTTP::Accept::Languages::Locales.new(["en-nz", "en-us"])
|
97
|
-
|
98
|
-
# Given the languages that the user wants, and the localizations available, compute the set of desired localizations.
|
99
|
-
desired_localizations = available_localizations & languages
|
100
|
-
```
|
101
|
-
|
102
|
-
The `desired_localizations` in the example above is a subset of `available_localizations`.
|
103
|
-
|
104
|
-
`HTTP::Accept::Languages::Locales` provides an efficient data-structure for matching the Accept-Languages header to set of available localizations according to https://tools.ietf.org/html/rfc7231#section-5.3.5 and https://tools.ietf.org/html/rfc4647#section-2.3
|
105
|
-
|
106
|
-
## Contributing
|
107
|
-
|
108
|
-
1. Fork it
|
109
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
110
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
111
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
112
|
-
5. Create new Pull Request
|
113
|
-
|
114
|
-
## License
|
115
|
-
|
116
|
-
Released under the MIT license.
|
117
|
-
|
118
|
-
Copyright, 2016, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
119
|
-
Copyright, 2016, by [Matthew Kerwin](http://kerwin.net.au).
|
120
|
-
|
121
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
122
|
-
of this software and associated documentation files (the "Software"), to deal
|
123
|
-
in the Software without restriction, including without limitation the rights
|
124
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
125
|
-
copies of the Software, and to permit persons to whom the Software is
|
126
|
-
furnished to do so, subject to the following conditions:
|
127
|
-
|
128
|
-
The above copyright notice and this permission notice shall be included in
|
129
|
-
all copies or substantial portions of the Software.
|
130
|
-
|
131
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
132
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
133
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
134
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
135
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
136
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
137
|
-
THE SOFTWARE.
|
data/Rakefile
DELETED
data/http-accept.gemspec
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
|
2
|
-
require_relative 'lib/http/accept/version'
|
3
|
-
|
4
|
-
Gem::Specification.new do |spec|
|
5
|
-
spec.name = "http-accept"
|
6
|
-
spec.version = HTTP::Accept::VERSION
|
7
|
-
spec.authors = ["Samuel Williams"]
|
8
|
-
spec.email = ["samuel.williams@oriontransfer.co.nz"]
|
9
|
-
|
10
|
-
spec.summary = %q{Parse Accept and Accept-Language HTTP headers.}
|
11
|
-
spec.homepage = "https://github.com/ioquatix/http-accept"
|
12
|
-
spec.license = 'MIT'
|
13
|
-
|
14
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
15
|
-
spec.bindir = "exe"
|
16
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
17
|
-
spec.require_paths = ["lib"]
|
18
|
-
|
19
|
-
spec.add_development_dependency "covered"
|
20
|
-
spec.add_development_dependency "bundler"
|
21
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
23
|
-
end
|