Skip to content

Commit 33f4784

Browse files
committed
Initial commit
0 parents  commit 33f4784

24 files changed

+896
-0
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
end_of_line = lf
9+
insert_final_newline = true
10+
indent_style = space
11+
indent_size = 4
12+
trim_trailing_whitespace = true

.gitattributes

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Path-based git attributes
2+
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
3+
4+
# Ignore all test and documentation with "export-ignore".
5+
/.gitattributes export-ignore
6+
/.gitignore export-ignore
7+
/.travis.yml export-ignore
8+
/phpunit.xml.dist export-ignore
9+
/.scrutinizer.yml export-ignore
10+
/tests export-ignore
11+
/CONTRIBUTING.md export-ignore
12+
/README.md export-ignore
13+
/server-push.png export-ignore

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
build
2+
composer.lock
3+
docs
4+
vendor
5+
.phpunit.result.cache
6+
.phpunit.cache

CONTRIBUTING.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Contributing
2+
3+
Contributions are **welcome** and will be fully **credited**.
4+
5+
We accept contributions via Pull Requests on [Github](https://github.com/justbetter/laravel-http3earlyhints).
6+
7+
8+
## Pull Requests
9+
10+
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).
11+
12+
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
13+
14+
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
15+
16+
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
17+
18+
- **Create feature branches** - Don't ask us to pull from your master branch.
19+
20+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
21+
22+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
23+
24+
25+
## Running Tests
26+
27+
``` bash
28+
$ phpunit
29+
```
30+
31+
**Happy coding**!

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# The MIT License (MIT)
2+
3+
Copyright (c) 2023 JustBetter
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.

README.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Early Hints Middleware for Laravel
2+
3+
Early Hints is a HTTP/3 concept which allows the server to send preconnect and preload headers while it's still preparing a response.
4+
This allows the broser to start loading these resources before the server has finished building and sending a response
5+
[See](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/103).
6+
7+
This package aims to provide the _easiest_ experience for adding Early Hints to your responses.
8+
Simply route your requests through the `AddHttp3EarlyHints` middleware and it will automatically create and attach the `Link` headers necessary to implement Early Hints for your CSS, JS and Image assets.
9+
10+
## Installation
11+
12+
You can install the package via composer:
13+
``` bash
14+
$ composer require justbetter/laravel-http3earlyhints
15+
```
16+
17+
Next you must add the `\JustBetter\Http3EarlyHints\Middleware\AddHttp3EarlyHints`-middleware to the kernel. Adding it to the web group is recommeneded as API's do not have assets to push.
18+
```php
19+
// app/Http/Kernel.php
20+
21+
...
22+
protected $middlewareGroups = [
23+
'web' => [
24+
...
25+
\JustBetter\Http3EarlyHints\Middleware\AddHttp3EarlyHints::class,
26+
...
27+
],
28+
...
29+
];
30+
```
31+
32+
## Publish config
33+
34+
```php
35+
php artisan vendor:publish --provider="JustBetter\Http3EarlyHints\ServiceProvider"
36+
```
37+
38+
39+
## Usage
40+
41+
When you route a request through the `AddHttp3EarlyHints` middleware, the response is scanned for any `link`, `script` or `img` tags that could benefit from being loaded using Early Hints.
42+
These assets will be added to the `Link` header before sending the response to the client. Easy!
43+
44+
**Note:** To push an image asset, it must have one of the following extensions: `bmp`, `gif`, `jpg`, `jpeg`, `png`, `tiff` or `svg` and not have loading="lazy"
45+
46+
## Testing
47+
48+
``` bash
49+
$ composer test
50+
```
51+
52+
## Contributing
53+
54+
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
55+
56+
## License
57+
58+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

composer.json

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"name": "justbetter/laravel-http3earlyhints",
3+
"description": "A HTTP3 Early Hints Middleware for Laravel",
4+
"keywords": [
5+
"laravel",
6+
"laravel-http3earlyhints",
7+
"serverpush",
8+
"http/3",
9+
"early hints"
10+
],
11+
"homepage": "https://github.com/justbetter/laravel-http3earlyhints",
12+
"license": "MIT",
13+
"authors": [
14+
{
15+
"name": "Indy Koning",
16+
"email": "[email protected]",
17+
"role": "Developer"
18+
}
19+
],
20+
"require": {
21+
"php" : "^8.0",
22+
"laravel/framework": "^10.0|^11.0",
23+
"symfony/dom-crawler": "^6.0|^7.0",
24+
"symfony/css-selector": "^6.0|^7.0"
25+
},
26+
"require-dev": {
27+
"laravel/pint": "^1.7",
28+
"larastan/larastan": "^2.5",
29+
"phpstan/phpstan-mockery": "^1.1",
30+
"phpunit/phpunit": "^10.1",
31+
"orchestra/testbench": "^8.0|^9.0"
32+
},
33+
"autoload": {
34+
"psr-4": {
35+
"JustBetter\\Http3EarlyHints\\": "src"
36+
}
37+
},
38+
"autoload-dev": {
39+
"psr-4": {
40+
"JustBetter\\Http3EarlyHints\\Tests\\": "tests"
41+
}
42+
},
43+
"scripts": {
44+
"test": "phpunit",
45+
"analyse": "phpstan",
46+
"style": "pint --test",
47+
"quality": [
48+
"@test",
49+
"@analyse",
50+
"@style"
51+
],
52+
"fix-style": "pint"
53+
},
54+
"extra": {
55+
"laravel": {
56+
"providers": [
57+
"JustBetter\\Http3EarlyHints\\ServiceProvider"
58+
]
59+
}
60+
}
61+
}

phpstan.neon

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
includes:
2+
- ./vendor/larastan/larastan/extension.neon
3+
- ./vendor/phpstan/phpstan-mockery/extension.neon
4+
5+
parameters:
6+
paths:
7+
- src
8+
- tests
9+
level: 4
10+
checkMissingIterableValueType: false

phpunit.xml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<testsuites>
4+
<testsuite name="Tests">
5+
<directory>tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<source>
9+
<include>
10+
<directory suffix=".php">src/</directory>
11+
</include>
12+
</source>
13+
<php>
14+
<env name="APP_ENV" value="testing"/>
15+
<env name="CACHE_DRIVER" value="array"/>
16+
<env name="SESSION_DRIVER" value="array"/>
17+
<env name="QUEUE_DRIVER" value="sync"/>
18+
<env name="DB_CONNECTION" value="sqlite"/>
19+
<env name="DB_DATABASE" value=":memory:"/>
20+
</php>
21+
</phpunit>

0 commit comments

Comments
 (0)