http-accept 2.2.0 → 2.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df0246f182c9234cb68ea3049b0db11f86c503bfc53a7e72fa4f7ecc13da7151
4
- data.tar.gz: a07dea0b41e4c7a0962e8be0543e7f714b7d1a20cf820cd413d90acaf0a1a0e1
3
+ metadata.gz: 744d60056b2386b45fad957f49be310a0672f276cb5528fbea605ca28759f332
4
+ data.tar.gz: 64a14c45a36902a23b639b0be824351ad89afb8a4f8dd8180e6b15d2539fe6ef
5
5
  SHA512:
6
- metadata.gz: 0b030b40a094e4b46726aa5e20a4c1b89b332218c165d2b1667159528229446b45cdc34c624acc7a90aed4cdd4dae663d125e61697825739b61abb01f255d4b5
7
- data.tar.gz: cdcd43429064dd0510cd6333a76f707e9fae42f5388316e5a977bfe34caf24c0ff047ffb08cdbcdb109d553b844857d55b765b48cbde60058ea57d8170762ac1
6
+ metadata.gz: 72049ca8a11284d8e82e559c9481b5345b76bfbe5a8918fb226e19a1bbc24e99bac93d37170004e51b5c2477812ae54f1c83ac65a7babfef6b13f3370e64daa9
7
+ data.tar.gz: 411d59f42dc93540c9a33c7f1b99ee7b7c9ebef40c9841a452a58a857160fb1777521289b2e93cfa8e9b1d9c5465eb50c0e48cc98054ee0faf524e4a64c983d4
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,24 +1,8 @@
1
1
  # frozen_string_literal: true
2
- #
3
- # Copyright (C) 2016, Matthew Kerwin <matthew@kerwin.net.au>
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.
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016, by Matthew Kerwin.
5
+ # Copyright, 2017-2024, by Samuel Williams.
22
6
 
23
7
  require 'strscan'
24
8
 
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
- #
3
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
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.
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016-2024, by Samuel Williams.
22
5
 
23
6
  require_relative 'media_types'
24
7
  require_relative 'quoted_string'
@@ -1,24 +1,8 @@
1
1
  # frozen_string_literal: true
2
- #
3
- # Copyright (C) 2016, Matthew Kerwin <matthew@kerwin.net.au>
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.
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016, by Matthew Kerwin.
5
+ # Copyright, 2017-2024, by Samuel Williams.
22
6
 
23
7
  require 'strscan'
24
8
 
@@ -1,24 +1,8 @@
1
1
  # frozen_string_literal: true
2
- #
3
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
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.
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016-2024, by Samuel Williams.
5
+ # Copyright, 2021, by Khaled Hassan Hussein.
22
6
 
23
7
  require 'strscan'
24
8
 
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
- #
3
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
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.
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016-2024, by Samuel Williams.
22
5
 
23
6
  module HTTP
24
7
  module Accept
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
- #
3
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
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.
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016-2024, by Samuel Williams.
22
5
 
23
6
  require 'strscan'
24
7
 
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
- #
3
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
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.
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016-2024, by Samuel Williams.
22
5
 
23
6
  module HTTP
24
7
  module Accept
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
- #
3
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
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.
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016-2024, by Samuel Williams.
22
5
 
23
6
  module HTTP
24
7
  module Accept
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
- #
3
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
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.
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016-2024, by Samuel Williams.
22
5
 
23
6
  module HTTP
24
7
  module Accept
@@ -1,27 +1,10 @@
1
1
  # frozen_string_literal: true
2
- #
3
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
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.
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016-2024, by Samuel Williams.
22
5
 
23
6
  module HTTP
24
7
  module Accept
25
- VERSION = "2.2.0"
8
+ VERSION = "2.2.1"
26
9
  end
27
10
  end
data/lib/http/accept.rb CHANGED
@@ -1,24 +1,9 @@
1
1
  # frozen_string_literal: true
2
- #
3
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
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.
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016-2024, by Samuel Williams.
5
+ # Copyright, 2016, by Matthew Kerwin.
6
+ # Copyright, 2017, by Andy Brody.
22
7
 
23
8
  require_relative 'accept/version'
24
9
 
data/license.md ADDED
@@ -0,0 +1,28 @@
1
+ # MIT License
2
+
3
+ Copyright, 2016-2024, by Samuel Williams.
4
+ Copyright, 2016, by Matthew Kerwin.
5
+ Copyright, 2016, by Alif Rachmawadi.
6
+ Copyright, 2017, by Andy Brody.
7
+ Copyright, 2019, by Robert Pritzkow.
8
+ Copyright, 2020, by Olle Jonsson.
9
+ Copyright, 2021, by Khaled Hassan Hussein.
10
+ Copyright, 2022, by Ian Oxley.
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,126 @@
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
+ [![Development Status](https://github.com/socketry/http-accept/workflows/Test/badge.svg)](https://github.com/socketry/http-accept/actions?workflow=Test)
6
+
7
+ ## Motivation
8
+
9
+ 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/).
10
+
11
+ 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.
12
+
13
+ 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.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ``` ruby
20
+ gem 'http-accept'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install http-accept
30
+
31
+ You can then require it in your code like so:
32
+
33
+ ``` ruby
34
+ require 'http/accept'
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ Here are some examples of how to parse various headers.
40
+
41
+ ### Parsing Accept: headers
42
+
43
+ You can parse the incoming `Accept:` header:
44
+
45
+ ``` ruby
46
+ media_types = HTTP::Accept::MediaTypes.parse("text/html;q=0.5, application/json; version=1")
47
+
48
+ expect(media_types[0].mime_type).to be == "application/json"
49
+ expect(media_types[0].parameters).to be == {'version' => '1'}
50
+ expect(media_types[1].mime_type).to be == "text/html"
51
+ expect(media_types[1].parameters).to be == {'q' => '0.5'}
52
+ ```
53
+
54
+ Normally, you'd want to match the media types against some set of available mime types:
55
+
56
+ ``` ruby
57
+ module ToJSON
58
+ def content_type
59
+ HTTP::Accept::ContentType.new("application", "json", charset: 'utf-8')
60
+ end
61
+
62
+ # Used for inserting into map.
63
+ def split(*args)
64
+ content_type.split(*args)
65
+ end
66
+
67
+ def convert(object, options)
68
+ object.to_json
69
+ end
70
+ end
71
+
72
+ module ToXML
73
+ # Are you kidding?
74
+ end
75
+
76
+ map = HTTP::Accept::MediaTypes::Map.new
77
+ map << ToJSON
78
+ map << ToXML
79
+
80
+ object, media_range = map.for(media_types)
81
+ content = object.convert(model, media_range.parameters)
82
+ response = [200, {'Content-Type' => object.content_type}, [content]]
83
+ ```
84
+
85
+ ### Parsing Accept-Language: headers
86
+
87
+ You can parse the incoming `Accept-Language:` header:
88
+
89
+ ``` ruby
90
+ languages = HTTP::Accept::Languages.parse("da, en-gb;q=0.8, en;q=0.7")
91
+
92
+ expect(languages[0].locale).to be == "da"
93
+ expect(languages[1].locale).to be == "en-gb"
94
+ expect(languages[2].locale).to be == "en"
95
+ ```
96
+
97
+ Normally, you'd want to match the languages against some set of available localizations:
98
+
99
+ ``` ruby
100
+ available_localizations = HTTP::Accept::Languages::Locales.new(["en-nz", "en-us"])
101
+
102
+ # Given the languages that the user wants, and the localizations available, compute the set of desired localizations.
103
+ desired_localizations = available_localizations & languages
104
+ ```
105
+
106
+ The `desired_localizations` in the example above is a subset of `available_localizations`.
107
+
108
+ `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>
109
+
110
+ ## Contributing
111
+
112
+ We welcome contributions to this project.
113
+
114
+ 1. Fork it.
115
+ 2. Create your feature branch (`git checkout -b my-new-feature`).
116
+ 3. Commit your changes (`git commit -am 'Add some feature'`).
117
+ 4. Push to the branch (`git push origin my-new-feature`).
118
+ 5. Create new Pull Request.
119
+
120
+ ### Developer Certificate of Origin
121
+
122
+ This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.
123
+
124
+ ### Contributor Covenant
125
+
126
+ This project is governed by the [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-accept
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  - Matthew Kerwin
9
9
  - Alif Rachmawadi
10
10
  - Andy Brody
11
+ - Ian Oxley
11
12
  - Khaled Hassan Hussein
12
13
  - Olle Jonsson
13
14
  - Robert Pritzkow
@@ -16,76 +17,35 @@ bindir: bin
16
17
  cert_chain:
17
18
  - |
18
19
  -----BEGIN CERTIFICATE-----
19
- MIIEhDCCAuygAwIBAgIBATANBgkqhkiG9w0BAQsFADA3MTUwMwYDVQQDDCxzYW11
20
- ZWwud2lsbGlhbXMvREM9b3Jpb250cmFuc2Zlci9EQz1jby9EQz1uejAeFw0yMTA4
21
- MTYwNjMzNDRaFw0yMjA4MTYwNjMzNDRaMDcx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D0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
44
46
  -----END CERTIFICATE-----
45
- date: 2022-08-02 00:00:00.000000000 Z
46
- dependencies:
47
- - !ruby/object:Gem::Dependency
48
- name: bundler
49
- requirement: !ruby/object:Gem::Requirement
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
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: '0'
61
- - !ruby/object:Gem::Dependency
62
- name: covered
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: '0'
68
- type: :development
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: '0'
75
- - !ruby/object:Gem::Dependency
76
- name: rspec
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - "~>"
80
- - !ruby/object:Gem::Version
81
- version: '3.0'
82
- type: :development
83
- prerelease: false
84
- version_requirements: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - "~>"
87
- - !ruby/object:Gem::Version
88
- version: '3.0'
47
+ date: 2024-02-05 00:00:00.000000000 Z
48
+ dependencies: []
89
49
  description:
90
50
  email:
91
51
  executables: []
@@ -104,6 +64,8 @@ files:
104
64
  - lib/http/accept/quoted_string.rb
105
65
  - lib/http/accept/sort.rb
106
66
  - lib/http/accept/version.rb
67
+ - license.md
68
+ - readme.md
107
69
  homepage: https://github.com/ioquatix/http-accept
108
70
  licenses:
109
71
  - MIT
@@ -117,14 +79,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
79
  requirements:
118
80
  - - ">="
119
81
  - !ruby/object:Gem::Version
120
- version: '0'
82
+ version: '3.0'
121
83
  required_rubygems_version: !ruby/object:Gem::Requirement
122
84
  requirements:
123
85
  - - ">="
124
86
  - !ruby/object:Gem::Version
125
87
  version: '0'
126
88
  requirements: []
127
- rubygems_version: 3.3.7
89
+ rubygems_version: 3.5.3
128
90
  signing_key:
129
91
  specification_version: 4
130
92
  summary: Parse Accept and Accept-Language HTTP headers.
metadata.gz.sig CHANGED
Binary file