fix: use http cookie for subpath proxying, referer header is firefox only
This commit is contained in:
parent
5d06b7b2dd
commit
24bae2ac48
4 changed files with 14 additions and 26 deletions
1
entemu/.gitignore
vendored
1
entemu/.gitignore
vendored
|
@ -11,3 +11,4 @@ _fresh/
|
|||
node_modules/
|
||||
vendor/
|
||||
|
||||
.npmrc
|
||||
|
|
|
@ -19,15 +19,6 @@ button {
|
|||
background: none;
|
||||
border: 1px solid var(--fore);
|
||||
border-radius: 4px;
|
||||
/*
|
||||
font: inherit;
|
||||
font-size: 1rem;
|
||||
border: none;
|
||||
padding: 4px;
|
||||
background-color: var(--back);
|
||||
border-radius: 1em;
|
||||
width: 2.2rem;
|
||||
*/
|
||||
}
|
||||
button, [role="button"] {
|
||||
cursor: pointer;
|
||||
|
|
2
junk.css
2
junk.css
|
@ -11,7 +11,7 @@ body {
|
|||
margin: 1em auto;
|
||||
width: 21cm;
|
||||
max-width: 100%;
|
||||
padding: 8px 0;
|
||||
padding: 0 8px;
|
||||
line-height: 1.5;
|
||||
background-color: var(--back);
|
||||
color: var(--fore);
|
||||
|
|
22
main.go
22
main.go
|
@ -64,24 +64,20 @@ func cmain(argc int, argv []string) string {
|
|||
cmdmap := map[string]JunkConf{}
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
p1 := r.URL.Path
|
||||
if p1 == "/" {
|
||||
fileserver.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
p := strings.Split(p1, "/")[1:]
|
||||
seg := p[0]
|
||||
if ref := r.Header.Get("Referer"); ref != "" {
|
||||
rurl, err := url.Parse(ref)
|
||||
rp := strings.Split(rurl.Path, "/")[1:]
|
||||
if rurl.Path != "/" {
|
||||
rseg := rp[0]
|
||||
if err == nil && seg != rseg && (len(p) < 2 || p[1] != rseg) {
|
||||
p1 = "/" + rseg + r.URL.Path
|
||||
w.Header().Set("Location", p1)
|
||||
vc, err := r.Cookie("view")
|
||||
if err != nil {
|
||||
w.Header().Add("Set-Cookie", "view="+seg+"; Path=/; SameSite=Strict; HttpOnly")
|
||||
w.Header().Add("Location", p1)
|
||||
w.WriteHeader(http.StatusFound)
|
||||
return
|
||||
}
|
||||
}
|
||||
v := vc.Value
|
||||
if seg != v {
|
||||
w.Header().Add("Location", "/"+v+p1)
|
||||
w.WriteHeader(http.StatusFound)
|
||||
return
|
||||
}
|
||||
if conf, ok := cmdmap[seg]; ok {
|
||||
proxy_path := conf.Proxy + "/" + strings.Join(p[1:], "/")
|
||||
|
|
Loading…
Reference in a new issue