http-accept 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/http/accept/languages.rb +1 -1
- data/lib/http/accept/media_types.rb +38 -13
- data/lib/http/accept/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 326c4ed19982fc140d5b4d9c691b99333f12e679
|
4
|
+
data.tar.gz: 5bacffff48f9a58e8eca3fb045591ef35d787398
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fff4f229ca636f688d921a81f8f62fa585eda081680827dea0a63ade5f834c9620438afdbff51301619417ce3da5dcffe12a46cad9a40d57305bbe1f999e73a7
|
7
|
+
data.tar.gz: 3b11ffa81002bac08ab011ad45a41ce598b3254d56c690951405901d0514bb337dd5fcfbf834e23665a2ca9f771e61616da44aaa9be999f966c51093810bdcf0
|
data/README.md
CHANGED
@@ -76,7 +76,7 @@ module HTTP
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
|
79
|
+
MediaRange = Struct.new(:mime_type, :parameters) do
|
80
80
|
def parameters_string
|
81
81
|
return '' if parameters == nil or parameters.empty?
|
82
82
|
|
@@ -107,22 +107,28 @@ module HTTP
|
|
107
107
|
mime_type.split(on, count)
|
108
108
|
end
|
109
109
|
|
110
|
+
def self.parse_parameters(scanner, normalize_whitespace)
|
111
|
+
parameters = {}
|
112
|
+
|
113
|
+
while scanner.scan(PARAMETER)
|
114
|
+
key = scanner[:key]
|
115
|
+
|
116
|
+
# If the regular expression PARAMETER matched, it must be one of these two:
|
117
|
+
if value = scanner[:value]
|
118
|
+
parameters[key] = value
|
119
|
+
elsif quoted_value = scanner[:quoted_value]
|
120
|
+
parameters[key] = QuotedString.unquote(quoted_value, normalize_whitespace)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
return parameters
|
125
|
+
end
|
126
|
+
|
110
127
|
def self.parse(scanner, normalize_whitespace = true)
|
111
128
|
return to_enum(:parse, scanner, normalize_whitespace) unless block_given?
|
112
129
|
|
113
130
|
while mime_type = scanner.scan(MIME_TYPE)
|
114
|
-
parameters =
|
115
|
-
|
116
|
-
while scanner.scan(PARAMETER)
|
117
|
-
key = scanner[:key]
|
118
|
-
|
119
|
-
# If the regular expression PARAMETER matched, it must be one of these two:
|
120
|
-
if value = scanner[:value]
|
121
|
-
parameters[key] = value
|
122
|
-
elsif quoted_value = scanner[:quoted_value]
|
123
|
-
parameters[key] = QuotedString.unquote(quoted_value, normalize_whitespace)
|
124
|
-
end
|
125
|
-
end
|
131
|
+
parameters = parse_parameters(scanner, normalize_whitespace)
|
126
132
|
|
127
133
|
yield self.new(mime_type, parameters)
|
128
134
|
|
@@ -141,6 +147,25 @@ module HTTP
|
|
141
147
|
|
142
148
|
return Sort.by_quality_factor(media_types)
|
143
149
|
end
|
150
|
+
|
151
|
+
HTTP_ACCEPT = 'HTTP_ACCEPT'.freeze
|
152
|
+
WILDCARD_MEDIA_RANGE = MediaRange.new("*/*", {}).freeze
|
153
|
+
|
154
|
+
# 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.
|
155
|
+
def self.browser_preferred_media_types(env)
|
156
|
+
if accept_content_types = env[HTTP_ACCEPT]
|
157
|
+
accept_content_types.strip!
|
158
|
+
|
159
|
+
unless accept_content_types.empty?
|
160
|
+
return HTTP::Accept::MediaTypes.parse(accept_content_types)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
# According to http://tools.ietf.org/html/rfc7231#section-5.3.2:
|
165
|
+
# A request without any Accept header field implies that the user agent will accept any media type in response.
|
166
|
+
# You should treat a non-existent Accept header as */*.
|
167
|
+
return [WILDCARD_MEDIA_RANGE]
|
168
|
+
end
|
144
169
|
end
|
145
170
|
end
|
146
171
|
end
|
data/lib/http/accept/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http-accept
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|