http-accept 1.7.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3b3754be244c82ac53b2ab75fcec39f8d34400fc
4
- data.tar.gz: ce62525b629b972c86c0073d567fba3e1690f7d1
2
+ SHA256:
3
+ metadata.gz: 744d60056b2386b45fad957f49be310a0672f276cb5528fbea605ca28759f332
4
+ data.tar.gz: 64a14c45a36902a23b639b0be824351ad89afb8a4f8dd8180e6b15d2539fe6ef
5
5
  SHA512:
6
- metadata.gz: 50a22597751d2dd3ed17ca4da33badae5c15d9941794763aaa199bdaff055b3edd6098cdc7ee6d932e7785069f57473ae054d6cef0a538703de6a245e949d841
7
- data.tar.gz: 3955b2cf2ce082c40fbace1a98fba58e62d01efb92f1f5e4f6e07b4ea87fbe79958d0fe7047a90ae871d7b6c5ceb34483bf676e66fa3615cc34bd43e08169da0
6
+ metadata.gz: 72049ca8a11284d8e82e559c9481b5345b76bfbe5a8918fb226e19a1bbc24e99bac93d37170004e51b5c2477812ae54f1c83ac65a7babfef6b13f3370e64daa9
7
+ data.tar.gz: 411d59f42dc93540c9a33c7f1b99ee7b7c9ebef40c9841a452a58a857160fb1777521289b2e93cfa8e9b1d9c5465eb50c0e48cc98054ee0faf524e4a64c983d4
checksums.yaml.gz.sig ADDED
Binary file
data/lib/.DS_Store ADDED
Binary file
@@ -1,22 +1,8 @@
1
- # Copyright (C) 2016, Matthew Kerwin <matthew@kerwin.net.au>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016, by Matthew Kerwin.
5
+ # Copyright, 2017-2024, by Samuel Williams.
20
6
 
21
7
  require 'strscan'
22
8
 
@@ -65,9 +51,7 @@ module HTTP
65
51
 
66
52
  # Parse the list of browser preferred charsets and return ordered by priority.
67
53
  def self.browser_preferred_charsets(env)
68
- if accept_charsets = env[HTTP_ACCEPT_CHARSET]
69
- accept_charsets.strip!
70
-
54
+ if accept_charsets = env[HTTP_ACCEPT_CHARSET]&.strip
71
55
  if accept_charsets.empty?
72
56
  # https://tools.ietf.org/html/rfc7231#section-5.3.3 :
73
57
  #
@@ -1,22 +1,7 @@
1
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016-2024, by Samuel Williams.
20
5
 
21
6
  require_relative 'media_types'
22
7
  require_relative 'quoted_string'
@@ -25,9 +10,9 @@ module HTTP
25
10
  module Accept
26
11
  # A content type is different from a media range, in that a content type should not have any wild cards.
27
12
  class ContentType < MediaTypes::MediaRange
28
- def initialize(mime_type, parameters = {})
13
+ def initialize(type, subtype, parameters = {})
29
14
  # We do some basic validation here:
30
- raise ArgumentError.new("#{self.class} can not have wildcards: #{mime_type}") if mime_type.include? '*'
15
+ raise ArgumentError.new("#{self.class} can not have wildcards: #{type}", "#{subtype}") if type.include?('*') || subtype.include?('*')
31
16
 
32
17
  super
33
18
  end
@@ -1,22 +1,8 @@
1
- # Copyright (C) 2016, Matthew Kerwin <matthew@kerwin.net.au>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016, by Matthew Kerwin.
5
+ # Copyright, 2017-2024, by Samuel Williams.
20
6
 
21
7
  require 'strscan'
22
8
 
@@ -72,9 +58,7 @@ module HTTP
72
58
  # specified, the behaviour is the same as if `Accept-Encoding: identity` was provided
73
59
  # (according to RFC).
74
60
  def self.browser_preferred_content_codings(env)
75
- if accept_content_codings = env[HTTP_ACCEPT_ENCODING]
76
- accept_content_codings.strip!
77
-
61
+ if accept_content_codings = env[HTTP_ACCEPT_ENCODING]&.strip
78
62
  if accept_content_codings.empty?
79
63
  # "An Accept-Encoding header field with a combined field-value that is
80
64
  # empty implies that the user agent does not want any content-coding in
@@ -1,22 +1,8 @@
1
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016-2024, by Samuel Williams.
5
+ # Copyright, 2021, by Khaled Hassan Hussein.
20
6
 
21
7
  require 'strscan'
22
8
 
@@ -30,7 +16,7 @@ module HTTP
30
16
  LOCALE = /\*|[A-Z]{1,8}(-[A-Z0-9]{1,8})*/i
31
17
 
32
18
  # https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.9
33
- QVALUE = /0(\.[0-9]{0,3})?|1(\.[0]{0,3})?/
19
+ QVALUE = /0(\.[0-9]{0,6})?|1(\.[0]{0,6})?/
34
20
 
35
21
  # https://greenbytes.de/tech/webdav/rfc7231.html#quality.values
36
22
  LANGUAGE_RANGE = /(?<locale>#{LOCALE})(\s*;\s*q=(?<q>#{QVALUE}))?/
@@ -1,22 +1,7 @@
1
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016-2024, by Samuel Williams.
20
5
 
21
6
  module HTTP
22
7
  module Accept
@@ -1,22 +1,7 @@
1
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016-2024, by Samuel Williams.
20
5
 
21
6
  require 'strscan'
22
7
 
@@ -31,11 +16,15 @@ module HTTP
31
16
  # Parse and process the HTTP Accept: header.
32
17
  module MediaTypes
33
18
  # According to https://tools.ietf.org/html/rfc7231#section-5.3.2
34
- MIME_TYPE = /(#{TOKEN})\/(#{TOKEN})/
19
+ MIME_TYPE = /(?<type>#{TOKEN})\/(?<subtype>#{TOKEN})/
35
20
  PARAMETER = /\s*;\s*(?<key>#{TOKEN})=((?<value>#{TOKEN})|(?<quoted_value>#{QUOTED_STRING}))/
36
21
 
37
22
  # A single entry in the Accept: header, which includes a mime type and associated parameters.
38
- MediaRange = Struct.new(:mime_type, :parameters) do
23
+ MediaRange = Struct.new(:type, :subtype, :parameters) do
24
+ def initialize(type, subtype = '*', parameters = {})
25
+ super(type, subtype, parameters)
26
+ end
27
+
39
28
  def parameters_string
40
29
  return '' if parameters == nil or parameters.empty?
41
30
 
@@ -52,8 +41,12 @@ module HTTP
52
41
  end
53
42
  end
54
43
 
44
+ def mime_type
45
+ "#{type}/#{subtype}"
46
+ end
47
+
55
48
  def to_s
56
- "#{mime_type}#{parameters_string}"
49
+ "#{type}/#{subtype}#{parameters_string}"
57
50
  end
58
51
 
59
52
  alias to_str to_s
@@ -62,8 +55,8 @@ module HTTP
62
55
  parameters.fetch('q', 1.0).to_f
63
56
  end
64
57
 
65
- def split(on = '/', count = 2)
66
- mime_type.split(on, count)
58
+ def split(*args)
59
+ return [type, subtype]
67
60
  end
68
61
 
69
62
  def self.parse_parameters(scanner, normalize_whitespace)
@@ -86,10 +79,13 @@ module HTTP
86
79
  def self.parse(scanner, normalize_whitespace = true)
87
80
  return to_enum(:parse, scanner, normalize_whitespace) unless block_given?
88
81
 
89
- while mime_type = scanner.scan(MIME_TYPE)
82
+ while scanner.scan(MIME_TYPE)
83
+ type = scanner[:type]
84
+ subtype = scanner[:subtype]
85
+
90
86
  parameters = parse_parameters(scanner, normalize_whitespace)
91
87
 
92
- yield self.new(mime_type, parameters)
88
+ yield self.new(type, subtype, parameters)
93
89
 
94
90
  # Are there more?
95
91
  break unless scanner.scan(/\s*,\s*/)
@@ -108,13 +104,11 @@ module HTTP
108
104
  end
109
105
 
110
106
  HTTP_ACCEPT = 'HTTP_ACCEPT'.freeze
111
- WILDCARD_MEDIA_RANGE = MediaRange.new("*/*", {}).freeze
107
+ WILDCARD_MEDIA_RANGE = MediaRange.new("*", "*", {}).freeze
112
108
 
113
109
  # Parse the list of browser preferred content types and return ordered by priority. If no `Accept:` header is specified, the behaviour is the same as if `Accept: */*` was provided (according to RFC).
114
110
  def self.browser_preferred_media_types(env)
115
- if accept_content_types = env[HTTP_ACCEPT]
116
- accept_content_types.strip!
117
-
111
+ if accept_content_types = env[HTTP_ACCEPT]&.strip
118
112
  unless accept_content_types.empty?
119
113
  return HTTP::Accept::MediaTypes.parse(accept_content_types)
120
114
  end
@@ -1,22 +1,7 @@
1
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016-2024, by Samuel Williams.
20
5
 
21
6
  module HTTP
22
7
  module Accept
@@ -1,22 +1,7 @@
1
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016-2024, by Samuel Williams.
20
5
 
21
6
  module HTTP
22
7
  module Accept
@@ -1,22 +1,7 @@
1
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016-2024, by Samuel Williams.
20
5
 
21
6
  module HTTP
22
7
  module Accept
@@ -1,25 +1,10 @@
1
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016-2024, by Samuel Williams.
20
5
 
21
6
  module HTTP
22
7
  module Accept
23
- VERSION = "1.7.0"
8
+ VERSION = "2.2.1"
24
9
  end
25
10
  end
data/lib/http/accept.rb CHANGED
@@ -1,24 +1,9 @@
1
- # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
20
2
 
21
- require "http/accept/version"
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.
@@ -2,9 +2,7 @@
2
2
 
3
3
  Provides a robust set of parsers for dealing with HTTP `Accept`, `Accept-Language`, `Accept-Encoding`, `Accept-Charset` headers.
4
4
 
5
- [![Build Status](https://secure.travis-ci.org/ioquatix/http-accept.svg)](http://travis-ci.org/ioquatix/http-accept)
6
- [![Code Climate](https://codeclimate.com/github/ioquatix/http-accept.svg)](https://codeclimate.com/github/ioquatix/http-accept)
7
- [![Coverage Status](https://coveralls.io/repos/ioquatix/http-accept/badge.svg)](https://coveralls.io/r/ioquatix/http-accept)
5
+ [![Development Status](https://github.com/socketry/http-accept/workflows/Test/badge.svg)](https://github.com/socketry/http-accept/actions?workflow=Test)
8
6
 
9
7
  ## Motivation
10
8
 
@@ -18,17 +16,23 @@ I am concerned about correctness, security and performance. As such, I implement
18
16
 
19
17
  Add this line to your application's Gemfile:
20
18
 
21
- ```ruby
19
+ ``` ruby
22
20
  gem 'http-accept'
23
21
  ```
24
22
 
25
23
  And then execute:
26
24
 
27
- $ bundle
25
+ $ bundle
28
26
 
29
27
  Or install it yourself as:
30
28
 
31
- $ gem install http-accept
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
+ ```
32
36
 
33
37
  ## Usage
34
38
 
@@ -38,7 +42,7 @@ Here are some examples of how to parse various headers.
38
42
 
39
43
  You can parse the incoming `Accept:` header:
40
44
 
41
- ```ruby
45
+ ``` ruby
42
46
  media_types = HTTP::Accept::MediaTypes.parse("text/html;q=0.5, application/json; version=1")
43
47
 
44
48
  expect(media_types[0].mime_type).to be == "application/json"
@@ -49,10 +53,10 @@ expect(media_types[1].parameters).to be == {'q' => '0.5'}
49
53
 
50
54
  Normally, you'd want to match the media types against some set of available mime types:
51
55
 
52
- ```ruby
56
+ ``` ruby
53
57
  module ToJSON
54
58
  def content_type
55
- HTTP::Accept::ContentType.new("application/json", charset: 'utf-8')
59
+ HTTP::Accept::ContentType.new("application", "json", charset: 'utf-8')
56
60
  end
57
61
 
58
62
  # Used for inserting into map.
@@ -82,7 +86,7 @@ response = [200, {'Content-Type' => object.content_type}, [content]]
82
86
 
83
87
  You can parse the incoming `Accept-Language:` header:
84
88
 
85
- ```ruby
89
+ ``` ruby
86
90
  languages = HTTP::Accept::Languages.parse("da, en-gb;q=0.8, en;q=0.7")
87
91
 
88
92
  expect(languages[0].locale).to be == "da"
@@ -92,7 +96,7 @@ expect(languages[2].locale).to be == "en"
92
96
 
93
97
  Normally, you'd want to match the languages against some set of available localizations:
94
98
 
95
- ```ruby
99
+ ``` ruby
96
100
  available_localizations = HTTP::Accept::Languages::Locales.new(["en-nz", "en-us"])
97
101
 
98
102
  # Given the languages that the user wants, and the localizations available, compute the set of desired localizations.
@@ -101,37 +105,22 @@ desired_localizations = available_localizations & languages
101
105
 
102
106
  The `desired_localizations` in the example above is a subset of `available_localizations`.
103
107
 
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
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>
105
109
 
106
110
  ## Contributing
107
111
 
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
112
+ We welcome contributions to this project.
115
113
 
116
- Released under the MIT license.
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.
117
119
 
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
+ ### Developer Certificate of Origin
120
121
 
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:
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.
127
123
 
128
- The above copyright notice and this permission notice shall be included in
129
- all copies or substantial portions of the Software.
124
+ ### Contributor Covenant
130
125
 
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.
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 ADDED
Binary file
metadata CHANGED
@@ -1,72 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http-accept
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
- autorequire:
9
- bindir: exe
10
- cert_chain: []
11
- date: 2017-03-14 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.11'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.11'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '10.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '10.0'
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.0'
55
- description:
8
+ - Matthew Kerwin
9
+ - Alif Rachmawadi
10
+ - Andy Brody
11
+ - Ian Oxley
12
+ - Khaled Hassan Hussein
13
+ - Olle Jonsson
14
+ - Robert Pritzkow
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain:
18
+ - |
19
+ -----BEGIN CERTIFICATE-----
20
+ MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11
21
+ ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK
22
+ CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz
23
+ MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd
24
+ MBsGCgmSJomT8ixkARkWDW9yaW9udHJhbnNmZXIxEjAQBgoJkiaJk/IsZAEZFgJj
25
+ bzESMBAGCgmSJomT8ixkARkWAm56MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIB
26
+ igKCAYEAomvSopQXQ24+9DBB6I6jxRI2auu3VVb4nOjmmHq7XWM4u3HL+pni63X2
27
+ 9qZdoq9xt7H+RPbwL28LDpDNflYQXoOhoVhQ37Pjn9YDjl8/4/9xa9+NUpl9XDIW
28
+ sGkaOY0eqsQm1pEWkHJr3zn/fxoKPZPfaJOglovdxf7dgsHz67Xgd/ka+Wo1YqoE
29
+ e5AUKRwUuvaUaumAKgPH+4E4oiLXI4T1Ff5Q7xxv6yXvHuYtlMHhYfgNn8iiW8WN
30
+ XibYXPNP7NtieSQqwR/xM6IRSoyXKuS+ZNGDPUUGk8RoiV/xvVN4LrVm9upSc0ss
31
+ RZ6qwOQmXCo/lLcDUxJAgG95cPw//sI00tZan75VgsGzSWAOdjQpFM0l4dxvKwHn
32
+ tUeT3ZsAgt0JnGqNm2Bkz81kG4A2hSyFZTFA8vZGhp+hz+8Q573tAR89y9YJBdYM
33
+ zp0FM4zwMNEUwgfRzv1tEVVUEXmoFCyhzonUUw4nE4CFu/sE3ffhjKcXcY//qiSW
34
+ xm4erY3XAgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
35
+ BBYEFO9t7XWuFf2SKLmuijgqR4sGDlRsMC4GA1UdEQQnMCWBI3NhbXVlbC53aWxs
36
+ aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWBI3NhbXVlbC53aWxs
37
+ aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEBCwUAA4IBgQB5sxkE
38
+ cBsSYwK6fYpM+hA5B5yZY2+L0Z+27jF1pWGgbhPH8/FjjBLVn+VFok3CDpRqwXCl
39
+ xCO40JEkKdznNy2avOMra6PFiQyOE74kCtv7P+Fdc+FhgqI5lMon6tt9rNeXmnW/
40
+ c1NaMRdxy999hmRGzUSFjozcCwxpy/LwabxtdXwXgSay4mQ32EDjqR1TixS1+smp
41
+ 8C/NCWgpIfzpHGJsjvmH2wAfKtTTqB9CVKLCWEnCHyCaRVuKkrKjqhYCdmMBqCws
42
+ JkxfQWC+jBVeG9ZtPhQgZpfhvh+6hMhraUYRQ6XGyvBqEUe+yo6DKIT3MtGE2+CP
43
+ eX9i9ZWBydWb8/rvmwmX2kkcBbX0hZS1rcR593hGc61JR6lvkGYQ2MYskBveyaxt
44
+ Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
45
+ voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
46
+ -----END CERTIFICATE-----
47
+ date: 2024-02-05 00:00:00.000000000 Z
48
+ dependencies: []
49
+ description:
56
50
  email:
57
- - samuel.williams@oriontransfer.co.nz
58
51
  executables: []
59
52
  extensions: []
60
53
  extra_rdoc_files: []
61
54
  files:
62
- - ".gitignore"
63
- - ".rspec"
64
- - ".simplecov"
65
- - ".travis.yml"
66
- - Gemfile
67
- - README.md
68
- - Rakefile
69
- - http-accept.gemspec
55
+ - lib/.DS_Store
70
56
  - lib/http/accept.rb
71
57
  - lib/http/accept/charsets.rb
72
58
  - lib/http/accept/content_type.rb
@@ -78,10 +64,14 @@ files:
78
64
  - lib/http/accept/quoted_string.rb
79
65
  - lib/http/accept/sort.rb
80
66
  - lib/http/accept/version.rb
67
+ - license.md
68
+ - readme.md
81
69
  homepage: https://github.com/ioquatix/http-accept
82
- licenses: []
83
- metadata: {}
84
- post_install_message:
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ funding_uri: https://github.com/sponsors/ioquatix/
74
+ post_install_message:
85
75
  rdoc_options: []
86
76
  require_paths:
87
77
  - lib
@@ -89,16 +79,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
79
  requirements:
90
80
  - - ">="
91
81
  - !ruby/object:Gem::Version
92
- version: '0'
82
+ version: '3.0'
93
83
  required_rubygems_version: !ruby/object:Gem::Requirement
94
84
  requirements:
95
85
  - - ">="
96
86
  - !ruby/object:Gem::Version
97
87
  version: '0'
98
88
  requirements: []
99
- rubyforge_project:
100
- rubygems_version: 2.6.10
101
- signing_key:
89
+ rubygems_version: 3.5.3
90
+ signing_key:
102
91
  specification_version: 4
103
92
  summary: Parse Accept and Accept-Language HTTP headers.
104
93
  test_files: []
metadata.gz.sig ADDED
@@ -0,0 +1,3 @@
1
+ p)�� 9��Ǖ\
2
+ /�0�ʯz_2�W�vt�)\�(cP؉U(�S�
3
+ �36����J�nb�Ŷ1]���f�lx���X�|��M��I&�� �@ya�� ��\�������${�b�~��*�ܮ�t:��[�}�9#�w'ê����æ ��d�At� ���m���ݞZ�>K͉D��pr[��^ �X�� ?5�t����3w���h��6�^ɐge� �$�(uE� � �h���/���;�C$E)�
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --color
2
- --format documentation
3
- --backtrace
4
- --warnings
data/.simplecov DELETED
@@ -1,9 +0,0 @@
1
-
2
- SimpleCov.start do
3
- add_filter "/spec/"
4
- end
5
-
6
- if ENV['TRAVIS']
7
- require 'coveralls'
8
- Coveralls.wear!
9
- end
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- env: COVERAGE=true
4
- rvm:
5
- - 2.3.0
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in http-accept.gemspec
4
- gemspec
5
-
6
- group :test do
7
- gem 'simplecov'
8
- gem 'coveralls', require: false
9
- end
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec) do |task|
5
- task.rspec_opts = ["--require", "simplecov"] if ENV['COVERAGE']
6
- end
7
-
8
- task :default => :spec
data/http-accept.gemspec DELETED
@@ -1,23 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'http/accept/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "http-accept"
8
- spec.version = HTTP::Accept::VERSION
9
- spec.authors = ["Samuel Williams"]
10
- spec.email = ["samuel.williams@oriontransfer.co.nz"]
11
-
12
- spec.summary = %q{Parse Accept and Accept-Language HTTP headers.}
13
- spec.homepage = "https://github.com/ioquatix/http-accept"
14
-
15
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
- spec.bindir = "exe"
17
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
- spec.require_paths = ["lib"]
19
-
20
- spec.add_development_dependency "bundler", "~> 1.11"
21
- spec.add_development_dependency "rake", "~> 10.0"
22
- spec.add_development_dependency "rspec", "~> 3.0"
23
- end