http-accept 1.7.0 → 2.1.0

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: 1b4a14e8a82f11fa25b5da2a13a3cf6ddd5e5ced9c02ba37950ff340390b3dc5
4
+ data.tar.gz: 57faa362d425e4ce3a0ee437874c235f2b16c98100adda81a315dadfc0740212
5
5
  SHA512:
6
- metadata.gz: 50a22597751d2dd3ed17ca4da33badae5c15d9941794763aaa199bdaff055b3edd6098cdc7ee6d932e7785069f57473ae054d6cef0a538703de6a245e949d841
7
- data.tar.gz: 3955b2cf2ce082c40fbace1a98fba58e62d01efb92f1f5e4f6e07b4ea87fbe79958d0fe7047a90ae871d7b6c5ceb34483bf676e66fa3615cc34bd43e08169da0
6
+ metadata.gz: f4cf41a3713b243bc9d4a0cfba2e459709191072d60ba23f864b852ab9d5c2cd5e5a8fc5d80783c2d798e03270f98e8913e866adcaed84f98ff489dcbf3a3567
7
+ data.tar.gz: eda8944a035fbda557a09e6f394fcd6691664ba8a7fd4acf91b8c94b67874c9b2afab3c5935003b0000799c27d1b031afd85138b7af432cd678b56fdf8347731
data/.gitignore CHANGED
@@ -1,9 +1,19 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .tags*
19
+ .rspec_status
data/.rspec CHANGED
@@ -1,4 +1,3 @@
1
- --color
2
1
  --format documentation
3
- --backtrace
4
- --warnings
2
+ --warnings
3
+ --require spec_helper
@@ -1,5 +1,21 @@
1
1
  language: ruby
2
- sudo: false
3
- env: COVERAGE=true
4
- rvm:
5
- - 2.3.0
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 CHANGED
@@ -2,8 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in http-accept.gemspec
4
4
  gemspec
5
-
6
- group :test do
7
- gem 'simplecov'
8
- gem 'coveralls', require: false
9
- end
data/README.md CHANGED
@@ -2,9 +2,9 @@
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
+ [![Build Status](https://secure.travis-ci.org/socketry/http-accept.svg)](http://travis-ci.org/socketry/http-accept)
6
+ [![Code Climate](https://codeclimate.com/github/socketry/http-accept.svg)](https://codeclimate.com/github/socketry/http-accept)
7
+ [![Coverage Status](https://coveralls.io/repos/socketry/http-accept/badge.svg)](https://coveralls.io/r/socketry/http-accept)
8
8
 
9
9
  ## Motivation
10
10
 
@@ -52,7 +52,7 @@ Normally, you'd want to match the media types against some set of available mime
52
52
  ```ruby
53
53
  module ToJSON
54
54
  def content_type
55
- HTTP::Accept::ContentType.new("application/json", charset: 'utf-8')
55
+ HTTP::Accept::ContentType.new("application", "json", charset: 'utf-8')
56
56
  end
57
57
 
58
58
  # Used for inserting into map.
@@ -115,7 +115,7 @@ The `desired_localizations` in the example above is a subset of `available_local
115
115
 
116
116
  Released under the MIT license.
117
117
 
118
- Copyright, 2016, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
118
+ Copyright, 2016, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
119
119
  Copyright, 2016, by [Matthew Kerwin](http://kerwin.net.au).
120
120
 
121
121
  Permission is hereby granted, free of charge, to any person obtaining a copy
data/Rakefile CHANGED
@@ -1,8 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
- RSpec::Core::RakeTask.new(:spec) do |task|
5
- task.rspec_opts = ["--require", "simplecov"] if ENV['COVERAGE']
6
- end
4
+ RSpec::Core::RakeTask.new(:spec)
7
5
 
8
6
  task :default => :spec
@@ -1,7 +1,5 @@
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'
1
+
2
+ require_relative 'lib/http/accept/version'
5
3
 
6
4
  Gem::Specification.new do |spec|
7
5
  spec.name = "http-accept"
@@ -17,7 +15,8 @@ Gem::Specification.new do |spec|
17
15
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
16
  spec.require_paths = ["lib"]
19
17
 
20
- spec.add_development_dependency "bundler", "~> 1.11"
18
+ spec.add_development_dependency "covered"
19
+ spec.add_development_dependency "bundler"
21
20
  spec.add_development_dependency "rake", "~> 10.0"
22
21
  spec.add_development_dependency "rspec", "~> 3.0"
23
22
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+ #
1
3
  # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -18,8 +20,6 @@
18
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
21
  # THE SOFTWARE.
20
22
 
21
- require "http/accept/version"
22
-
23
23
  require_relative 'accept/version'
24
24
 
25
25
  # Accept: header
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+ #
1
3
  # Copyright (C) 2016, Matthew Kerwin <matthew@kerwin.net.au>
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -65,9 +67,7 @@ module HTTP
65
67
 
66
68
  # Parse the list of browser preferred charsets and return ordered by priority.
67
69
  def self.browser_preferred_charsets(env)
68
- if accept_charsets = env[HTTP_ACCEPT_CHARSET]
69
- accept_charsets.strip!
70
-
70
+ if accept_charsets = env[HTTP_ACCEPT_CHARSET]&.strip
71
71
  if accept_charsets.empty?
72
72
  # https://tools.ietf.org/html/rfc7231#section-5.3.3 :
73
73
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+ #
1
3
  # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -25,9 +27,9 @@ module HTTP
25
27
  module Accept
26
28
  # A content type is different from a media range, in that a content type should not have any wild cards.
27
29
  class ContentType < MediaTypes::MediaRange
28
- def initialize(mime_type, parameters = {})
30
+ def initialize(type, subtype, parameters = {})
29
31
  # We do some basic validation here:
30
- raise ArgumentError.new("#{self.class} can not have wildcards: #{mime_type}") if mime_type.include? '*'
32
+ raise ArgumentError.new("#{self.class} can not have wildcards: #{type}", "#{subtype}") if type.include?('*') || subtype.include?('*')
31
33
 
32
34
  super
33
35
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+ #
1
3
  # Copyright (C) 2016, Matthew Kerwin <matthew@kerwin.net.au>
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -72,9 +74,7 @@ module HTTP
72
74
  # specified, the behaviour is the same as if `Accept-Encoding: identity` was provided
73
75
  # (according to RFC).
74
76
  def self.browser_preferred_content_codings(env)
75
- if accept_content_codings = env[HTTP_ACCEPT_ENCODING]
76
- accept_content_codings.strip!
77
-
77
+ if accept_content_codings = env[HTTP_ACCEPT_ENCODING]&.strip
78
78
  if accept_content_codings.empty?
79
79
  # "An Accept-Encoding header field with a combined field-value that is
80
80
  # empty implies that the user agent does not want any content-coding in
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+ #
1
3
  # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+ #
1
3
  # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -31,11 +33,11 @@ module HTTP
31
33
  # Parse and process the HTTP Accept: header.
32
34
  module MediaTypes
33
35
  # According to https://tools.ietf.org/html/rfc7231#section-5.3.2
34
- MIME_TYPE = /(#{TOKEN})\/(#{TOKEN})/
36
+ MIME_TYPE = /(?<type>#{TOKEN})\/(?<subtype>#{TOKEN})/
35
37
  PARAMETER = /\s*;\s*(?<key>#{TOKEN})=((?<value>#{TOKEN})|(?<quoted_value>#{QUOTED_STRING}))/
36
38
 
37
39
  # A single entry in the Accept: header, which includes a mime type and associated parameters.
38
- MediaRange = Struct.new(:mime_type, :parameters) do
40
+ MediaRange = Struct.new(:type, :subtype, :parameters) do
39
41
  def parameters_string
40
42
  return '' if parameters == nil or parameters.empty?
41
43
 
@@ -52,8 +54,12 @@ module HTTP
52
54
  end
53
55
  end
54
56
 
57
+ def mime_type
58
+ "#{type}/#{subtype}"
59
+ end
60
+
55
61
  def to_s
56
- "#{mime_type}#{parameters_string}"
62
+ "#{type}/#{subtype}#{parameters_string}"
57
63
  end
58
64
 
59
65
  alias to_str to_s
@@ -62,8 +68,8 @@ module HTTP
62
68
  parameters.fetch('q', 1.0).to_f
63
69
  end
64
70
 
65
- def split(on = '/', count = 2)
66
- mime_type.split(on, count)
71
+ def split(*args)
72
+ return [type, subtype]
67
73
  end
68
74
 
69
75
  def self.parse_parameters(scanner, normalize_whitespace)
@@ -86,10 +92,13 @@ module HTTP
86
92
  def self.parse(scanner, normalize_whitespace = true)
87
93
  return to_enum(:parse, scanner, normalize_whitespace) unless block_given?
88
94
 
89
- while mime_type = scanner.scan(MIME_TYPE)
95
+ while scanner.scan(MIME_TYPE)
96
+ type = scanner[:type]
97
+ subtype = scanner[:subtype]
98
+
90
99
  parameters = parse_parameters(scanner, normalize_whitespace)
91
100
 
92
- yield self.new(mime_type, parameters)
101
+ yield self.new(type, subtype, parameters)
93
102
 
94
103
  # Are there more?
95
104
  break unless scanner.scan(/\s*,\s*/)
@@ -108,13 +117,11 @@ module HTTP
108
117
  end
109
118
 
110
119
  HTTP_ACCEPT = 'HTTP_ACCEPT'.freeze
111
- WILDCARD_MEDIA_RANGE = MediaRange.new("*/*", {}).freeze
120
+ WILDCARD_MEDIA_RANGE = MediaRange.new("*", "*", {}).freeze
112
121
 
113
122
  # 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
123
  def self.browser_preferred_media_types(env)
115
- if accept_content_types = env[HTTP_ACCEPT]
116
- accept_content_types.strip!
117
-
124
+ if accept_content_types = env[HTTP_ACCEPT]&.strip
118
125
  unless accept_content_types.empty?
119
126
  return HTTP::Accept::MediaTypes.parse(accept_content_types)
120
127
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+ #
1
3
  # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+ #
1
3
  # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+ #
1
3
  # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+ #
1
3
  # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+ #
1
3
  # Copyright, 2016, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -20,6 +22,6 @@
20
22
 
21
23
  module HTTP
22
24
  module Accept
23
- VERSION = "1.7.0"
25
+ VERSION = "2.1.0"
24
26
  end
25
27
  end
metadata CHANGED
@@ -1,29 +1,43 @@
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.1.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: 2017-03-14 00:00:00.000000000 Z
11
+ date: 2019-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: covered
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - "~>"
31
+ - - ">="
18
32
  - !ruby/object:Gem::Version
19
- version: '1.11'
33
+ version: '0'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - "~>"
38
+ - - ">="
25
39
  - !ruby/object:Gem::Version
26
- version: '1.11'
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -61,7 +75,6 @@ extra_rdoc_files: []
61
75
  files:
62
76
  - ".gitignore"
63
77
  - ".rspec"
64
- - ".simplecov"
65
78
  - ".travis.yml"
66
79
  - Gemfile
67
80
  - README.md
@@ -96,8 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
109
  - !ruby/object:Gem::Version
97
110
  version: '0'
98
111
  requirements: []
99
- rubyforge_project:
100
- rubygems_version: 2.6.10
112
+ rubygems_version: 3.0.4
101
113
  signing_key:
102
114
  specification_version: 4
103
115
  summary: Parse Accept and Accept-Language HTTP headers.
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