mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-29 18:36:30 +02:00
Revert "userinfo: embed assets as data URLs for forward auth" (#3474)
Revert "userinfo: embed assets as data URLs for forward auth (#3460)"
This reverts commit 6c573282ee
.
This commit is contained in:
parent
8b2d0ce1db
commit
b4cbecc4fd
2 changed files with 0 additions and 57 deletions
|
@ -1,11 +0,0 @@
|
|||
package urlutil
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
)
|
||||
|
||||
// DataURL returns a data-url for the data.
|
||||
func DataURL(mediaType string, data []byte) string {
|
||||
bs := base64.StdEncoding.EncodeToString(data)
|
||||
return "data:" + mediaType + ";base64," + bs
|
||||
}
|
46
ui/embed.go
46
ui/embed.go
|
@ -5,17 +5,11 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"mime"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pomerium/csrf"
|
||||
"github.com/pomerium/pomerium/internal/urlutil"
|
||||
)
|
||||
|
||||
// ServeFile serves a file.
|
||||
|
@ -54,19 +48,6 @@ func ServePage(w http.ResponseWriter, r *http.Request, page string, data map[str
|
|||
return err
|
||||
}
|
||||
|
||||
re, err := regexp.Compile(`(src|href)="(.*?)"`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bs = re.ReplaceAllFunc(bs, func(b []byte) []byte {
|
||||
parts := re.FindStringSubmatch(string(b))
|
||||
if len(parts) < 3 {
|
||||
return b
|
||||
}
|
||||
return []byte(parts[1] + `="` + embedRelativeFileURL(parts[2]) + `"`)
|
||||
})
|
||||
|
||||
bs = bytes.Replace(bs,
|
||||
[]byte("window.POMERIUM_DATA = {}"),
|
||||
append([]byte("window.POMERIUM_DATA = "), jsonData...),
|
||||
|
@ -77,30 +58,3 @@ func ServePage(w http.ResponseWriter, r *http.Request, page string, data map[str
|
|||
}
|
||||
|
||||
var startTime = time.Now()
|
||||
|
||||
func embedRelativeFileURL(rawURL string) (dataURLOrOriginalURL string) {
|
||||
u, err := url.Parse(rawURL)
|
||||
if err != nil {
|
||||
return rawURL
|
||||
}
|
||||
|
||||
filePath := strings.Replace(u.Path, "/.pomerium/", "dist/", 1)
|
||||
f, _, err := openFile(filePath)
|
||||
if err != nil {
|
||||
return rawURL
|
||||
}
|
||||
bs, err := io.ReadAll(f)
|
||||
_ = f.Close()
|
||||
if err != nil {
|
||||
return rawURL
|
||||
}
|
||||
|
||||
mediaType := mime.TypeByExtension(path.Ext(rawURL))
|
||||
if mediaType == "" {
|
||||
mediaType = "application/octet-stream"
|
||||
}
|
||||
if idx := strings.Index(mediaType, ";"); idx >= 0 {
|
||||
mediaType = mediaType[:idx]
|
||||
}
|
||||
return urlutil.DataURL(mediaType, bs)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue