mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-27 10:47:06 +02:00
feat(auth): enhance cookieDomain function to support additional local domains
This commit is contained in:
@@ -3,6 +3,7 @@ package auth
|
|||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/yusing/go-proxy/internal/common"
|
"github.com/yusing/go-proxy/internal/common"
|
||||||
@@ -44,8 +45,21 @@ func requestHost(r *http.Request) string {
|
|||||||
//
|
//
|
||||||
// "abc.example.com" -> ".example.com" (cross subdomain)
|
// "abc.example.com" -> ".example.com" (cross subdomain)
|
||||||
// "example.com" -> "" (same domain only)
|
// "example.com" -> "" (same domain only)
|
||||||
|
// "abc.localhost" -> ".localhost"
|
||||||
|
// "abc.local" -> ".local"
|
||||||
|
// "abc.internal" -> ".internal"
|
||||||
func cookieDomain(r *http.Request) string {
|
func cookieDomain(r *http.Request) string {
|
||||||
parts := strutils.SplitRune(requestHost(r), '.')
|
reqHost := requestHost(r)
|
||||||
|
switch {
|
||||||
|
case strings.HasSuffix(reqHost, ".internal"):
|
||||||
|
return ".internal"
|
||||||
|
case strings.HasSuffix(reqHost, ".localhost"):
|
||||||
|
return ".localhost"
|
||||||
|
case strings.HasSuffix(reqHost, ".local"):
|
||||||
|
return ".local"
|
||||||
|
}
|
||||||
|
|
||||||
|
parts := strutils.SplitRune(reqHost, '.')
|
||||||
if len(parts) < 2 {
|
if len(parts) < 2 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user