Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with relative urls #27

Closed
Nuranto opened this issue Mar 2, 2019 · 0 comments
Closed

Error with relative urls #27

Nuranto opened this issue Mar 2, 2019 · 0 comments

Comments

@Nuranto
Copy link
Contributor

Nuranto commented Mar 2, 2019

When using relative URLs, it creates errors.

The patch could be quite simple, something like that :

diff --git a/src/Middleware/AddHttp2ServerPush.php b/src/Middleware/AddHttp2ServerPush.php
index 253cf28..adb94d8 100644
--- a/src/Middleware/AddHttp2ServerPush.php
+++ b/src/Middleware/AddHttp2ServerPush.php
@@ -115,7 +115,9 @@ class AddHttp2ServerPush
         $type = collect($linkTypeMap)->first(function ($type, $extension) use ($url) {
             return str_contains(strtoupper($url), $extension);
         });
-
+        if(!preg_match('%^https?://%i', $url)) {
+            $basePath = config('http2serverpush.base_path', '/');
+            $url = $basePath . ltrim($url, $basePath);
+        }
         return is_null($type) ? null : "<{$url}>; rel=preload; as={$type}";
     }

But it would require a config file...
In my case, base path is always '/'. But it could be any other path...

Nuranto added a commit to Nuranto/laravel-HTTP2ServerPush that referenced this issue Mar 15, 2019
- Add size limit
- Add base path configuration
- Add exceptions filters
- Update test
- Updates doc

solves JacobBennett#23, JacobBennett#27
JacobBennett pushed a commit that referenced this issue Sep 19, 2019
* #25 deduplicate header links

* - Add config file
- Add size limit
- Add base path configuration
- Add exceptions filters
- Update test
- Updates doc

solves #23, #27

* update travis :
- remove PHP5.6,
- add PHP7.2 and 7.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants