early_hints_header 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3f9c4dda9525bf1414aaa190e19b155ef1cc3614d87a78ba0975f0266c2e2d08
4
+ data.tar.gz: 171b758f20d848fa02f5aac5c0f6c068f9a9c35fae253fb7d752d324ed146a49
5
+ SHA512:
6
+ metadata.gz: 60510a78ddc33e8ecbb76668a82a155ea336c33071c4553fe679baec4f301e9fed72c2c67a67e5f749c5318ee66addca77d470330b243dc5aed42243fcd95016
7
+ data.tar.gz: a470a078a77f9de11a3c62e93119466665c92e121c837479c7ce52de572cb4f0ff41672ab8b5d2128a5f66fa84123693b09b794a97599ba10cf39a373ef835ee
@@ -0,0 +1,22 @@
1
+ ---
2
+ name: Ruby
3
+
4
+ on:
5
+ push:
6
+ branches: [master]
7
+ pull_request:
8
+ branches: [master]
9
+
10
+ jobs:
11
+ test:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - name: Set up Ruby
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: 2.6
19
+ - name: Install dependencies
20
+ run: bundle install
21
+ - name: Run tests
22
+ run: bundle exec rake
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [1.0.0] - 2020-05-14
11
+
12
+ ### Added
13
+
14
+ - Initial gem extraction from [@ianks](https://github.com/ianks).
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at i.kerseymer@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in early_hints_header.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "fast_woothee"
9
+ gem "rack"
10
+ gem "rack-test", group: :test
11
+ gem "standardrb"
@@ -0,0 +1,75 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ early_hints_header (1.0.0)
5
+ fast_woothee
6
+ rack
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.0)
12
+ diff-lcs (1.3)
13
+ fast_woothee (1.6.0)
14
+ thermite (~> 0.13.0)
15
+ jaro_winkler (1.5.4)
16
+ minitar (0.9)
17
+ parallel (1.19.1)
18
+ parser (2.7.1.2)
19
+ ast (~> 2.4.0)
20
+ rack (2.2.2)
21
+ rack-test (1.1.0)
22
+ rack (>= 1.0, < 3)
23
+ rainbow (3.0.0)
24
+ rake (12.3.3)
25
+ rexml (3.2.4)
26
+ rspec (3.9.0)
27
+ rspec-core (~> 3.9.0)
28
+ rspec-expectations (~> 3.9.0)
29
+ rspec-mocks (~> 3.9.0)
30
+ rspec-core (3.9.2)
31
+ rspec-support (~> 3.9.3)
32
+ rspec-expectations (3.9.2)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.9.0)
35
+ rspec-mocks (3.9.1)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.9.0)
38
+ rspec-support (3.9.3)
39
+ rubocop (0.82.0)
40
+ jaro_winkler (~> 1.5.1)
41
+ parallel (~> 1.10)
42
+ parser (>= 2.7.0.1)
43
+ rainbow (>= 2.2.2, < 4.0)
44
+ rexml
45
+ ruby-progressbar (~> 1.7)
46
+ unicode-display_width (>= 1.4.0, < 2.0)
47
+ rubocop-performance (1.5.2)
48
+ rubocop (>= 0.71.0)
49
+ ruby-progressbar (1.10.1)
50
+ standard (0.4.1)
51
+ rubocop (~> 0.82.0)
52
+ rubocop-performance (~> 1.5.2)
53
+ standardrb (1.0.0)
54
+ standard
55
+ thermite (0.13.0)
56
+ minitar (~> 0.5)
57
+ rake (>= 10)
58
+ tomlrb (~> 1.2)
59
+ tomlrb (1.3.0)
60
+ unicode-display_width (1.7.0)
61
+
62
+ PLATFORMS
63
+ ruby
64
+
65
+ DEPENDENCIES
66
+ early_hints_header!
67
+ fast_woothee
68
+ rack
69
+ rack-test
70
+ rake (~> 12.0)
71
+ rspec (~> 3.0)
72
+ standardrb
73
+
74
+ BUNDLED WITH
75
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Ian Ker-Seymer
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.
@@ -0,0 +1,75 @@
1
+ # EarlyHintsHeader
2
+
3
+ ![Ruby](https://github.com/ianks/early_hints_header/workflows/Ruby/badge.svg)
4
+
5
+ An early hints Ruby / Rack middleware which just sets Link headers.
6
+
7
+ This means you can use early hints _without_ having to use the HTTP 103
8
+ status code, i.e. [nginx's
9
+ http2_push_preload](https://www.nginx.com/blog/nginx-1-13-9-http2-server-push/#automatic-push).
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'early_hints_header'
17
+ gem 'fast_woothee' # optional: for blocking broken client like iOS
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle install
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install early_hints_header
27
+
28
+ ## Usage
29
+
30
+ ```ruby
31
+ # In config.ru
32
+
33
+ require "early_hints_header/middleware"
34
+
35
+ use EarlyHintsHeader::Middleware
36
+ ```
37
+
38
+ ## Caveats
39
+
40
+ When using HTTP2 push, be aware of potential clients that do not properly
41
+ support preloading. For example, [certain older Safari
42
+ versions](https://jakearchibald.com/2017/h2-push-tougher-than-i-thought/) do
43
+ not work properly. This gem will handle that if you have
44
+ [fast_woothee](https://github.com/ianks/fast_woothee) installed.
45
+
46
+ ## Development
47
+
48
+ After checking out the repo, run `bin/setup` to install dependencies. Then,
49
+ run `rake spec` to run the tests. You can also run `bin/console` for an
50
+ interactive prompt that will allow you to experiment.
51
+
52
+ To install this gem onto your local machine, run `bundle exec rake install`.
53
+ To release a new version, update the version number in `version.rb`, and then
54
+ run `bundle exec rake release`, which will create a git tag for the version,
55
+ push git commits and tags, and push the `.gem` file to
56
+ [rubygems.org](https://rubygems.org).
57
+
58
+ ## Contributing
59
+
60
+ Bug reports and pull requests are welcome on GitHub at
61
+ https://github.com/ianks/early_hints_header. This project is intended to
62
+ be a safe, welcoming space for collaboration, and contributors are expected
63
+ to adhere to the [code of
64
+ conduct](https://github.com/ianks/early_hints_header/blob/master/CODE_OF_CONDUCT.md).
65
+
66
+ ## License
67
+
68
+ The gem is available as open source under the terms of the [MIT
69
+ License](https://opensource.org/licenses/MIT).
70
+
71
+ ## Code of Conduct
72
+
73
+ Everyone interacting in the EarlyHintsHeader project's codebases, issue
74
+ trackers, chat rooms and mailing lists is expected to follow the [code of
75
+ conduct](https://github.com/ianks/early_hints_header/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "standard/rake"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: [:spec, :standard]
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "early_hints_header"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ require_relative "lib/early_hints_header/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "early_hints_header"
5
+ spec.version = EarlyHintsHeader::VERSION
6
+ spec.authors = ["Ian Ker-Seymer"]
7
+ spec.email = ["i.kerseymer@gmail.com"]
8
+
9
+ spec.summary = "An early hints Ruby / Rack middleware which just sets Link headers (i.e. for nginx http2_push_preload)"
10
+ spec.homepage = "https://github.com/ianks/early_hints_header"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/ianks/early_hints_header"
18
+ spec.metadata["changelog_uri"] = "https://github.com/ianks/early_hints_header/blob/master/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_runtime_dependency "fast_woothee"
30
+ spec.add_runtime_dependency "rack"
31
+ end
@@ -0,0 +1,7 @@
1
+ require "early_hints_header/version"
2
+ require "early_hints_header/middleware"
3
+
4
+ module EarlyHintsHeader
5
+ class Error < StandardError; end
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "fast_woothee"
5
+ rescue LoadError
6
+ # ok
7
+ end
8
+
9
+ module EarlyHintsHeader
10
+ class Middleware
11
+ RACK_KEY = "early_hints.links"
12
+
13
+ def initialize(app)
14
+ @app = app
15
+ end
16
+
17
+ def call(env)
18
+ env["rack.early_hints"] = proc do |header|
19
+ env[RACK_KEY] ||= []
20
+ env[RACK_KEY] << header["Link"]
21
+ end
22
+
23
+ status, headers, body = @app.call(env)
24
+ assign_headers(headers, env)
25
+ clear_thread_locals
26
+
27
+ [status, headers, body]
28
+ end
29
+
30
+ private
31
+
32
+ def build_link_header(headers, env)
33
+ links = [headers.delete("Link"), *env[RACK_KEY]]
34
+ links.compact!
35
+ links.join(",") if env.key?(RACK_KEY)
36
+ end
37
+
38
+ def clear_thread_locals
39
+ Thread.current[:__hanami_assets] = nil
40
+ end
41
+
42
+ def pushable?(env)
43
+ return true unless defined?(FastWoothee)
44
+ return false unless env.key?(RACK_KEY)
45
+
46
+ # ios caching with http2 push is unpredictable
47
+ !FastWoothee.ios?(env["HTTP_USER_AGENT"])
48
+ end
49
+
50
+ def assign_headers(headers, env)
51
+ return unless pushable?(env)
52
+
53
+ headers["Link"] = build_link_header(headers, env)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,3 @@
1
+ module EarlyHintsHeader
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: early_hints_header
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ian Ker-Seymer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-05-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fast_woothee
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - i.kerseymer@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".github/workflows/ruby.yml"
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - CHANGELOG.md
52
+ - CODE_OF_CONDUCT.md
53
+ - Gemfile
54
+ - Gemfile.lock
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - bin/console
59
+ - bin/setup
60
+ - early_hints_header.gemspec
61
+ - lib/early_hints_header.rb
62
+ - lib/early_hints_header/middleware.rb
63
+ - lib/early_hints_header/version.rb
64
+ homepage: https://github.com/ianks/early_hints_header
65
+ licenses:
66
+ - MIT
67
+ metadata:
68
+ allowed_push_host: https://rubygems.org
69
+ homepage_uri: https://github.com/ianks/early_hints_header
70
+ source_code_uri: https://github.com/ianks/early_hints_header
71
+ changelog_uri: https://github.com/ianks/early_hints_header/blob/master/CHANGELOG.md
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 2.3.0
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubygems_version: 3.1.2
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: An early hints Ruby / Rack middleware which just sets Link headers (i.e.
91
+ for nginx http2_push_preload)
92
+ test_files: []