Skip to content

Error with relative urls #27

@Nuranto

Description

@Nuranto

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions