Allow proxyURL to contain a path.
We now support or reasonable values for proxyURL, such as "http:" or "/galene".
This commit is contained in:
1 parent
6756e7f7cc
commit
29e006037c
6 files changed
+66
-47
No files matched your search
+27
-10
@@ -361,29 +361,44 @@ func groupHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
status := g.Status(false, "")
|
||||
status := g.Status(false, nil)
|
||||
cspHeader(w, status.AuthServer)
|
||||
serveFile(w, r, filepath.Join(StaticRoot, "galene.html"))
|
||||
}
|
||||
|
||||
func groupBase(r *http.Request) (string, error) {
|
||||
func baseURL(r *http.Request) (*url.URL, error) {
|
||||
conf, err := group.GetConfiguration()
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
var pu *url.URL
|
||||
if conf.ProxyURL != "" {
|
||||
return url.JoinPath(conf.ProxyURL, "/group/")
|
||||
pu, err = url.Parse(conf.ProxyURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
scheme := "https"
|
||||
if r.TLS == nil {
|
||||
scheme = "http"
|
||||
}
|
||||
host := r.Host
|
||||
path := ""
|
||||
if pu != nil {
|
||||
if pu.Scheme != "" {
|
||||
scheme = pu.Scheme
|
||||
}
|
||||
if pu.Host != "" {
|
||||
host = pu.Host
|
||||
}
|
||||
path = pu.Path
|
||||
}
|
||||
base := url.URL{
|
||||
Scheme: scheme,
|
||||
Host: r.Host,
|
||||
Path: "/group/",
|
||||
Host: host,
|
||||
Path: path,
|
||||
}
|
||||
return base.String(), nil
|
||||
return &base, nil
|
||||
}
|
||||
|
||||
func groupStatusHandler(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -404,9 +419,11 @@ func groupStatusHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
base, err := groupBase(r)
|
||||
base, err := baseURL(r)
|
||||
if err != nil {
|
||||
httpError(w, err)
|
||||
log.Printf("Parse ProxyURL: %v", err)
|
||||
http.Error(w, "Internal server error",
|
||||
http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
d := g.Status(false, base)
|
||||
@@ -422,7 +439,7 @@ func groupStatusHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func publicHandler(w http.ResponseWriter, r *http.Request) {
|
||||
base, err := groupBase(r)
|
||||
base, err := baseURL(r)
|
||||
if err != nil {
|
||||
log.Printf("couldn't determine group base: %v", err)
|
||||
httpError(w, err)
|
||||
|
||||
@@ -42,12 +42,18 @@ func TestBase(t *testing.T) {
|
||||
t bool
|
||||
h, res string
|
||||
}{
|
||||
{"", true, "a.org", "https://a.org/group/"},
|
||||
{"", false, "a.org", "http://a.org/group/"},
|
||||
{"https://b.org", true, "a.org", "https://b.org/group/"},
|
||||
{"https://b.org", false, "a.org", "https://b.org/group/"},
|
||||
{"http://b.org", true, "a.org", "http://b.org/group/"},
|
||||
{"http://b.org", false, "a.org", "http://b.org/group/"},
|
||||
{"", true, "a.org", "https://a.org"},
|
||||
{"", false, "a.org", "http://a.org"},
|
||||
{"/base", true, "a.org", "https://a.org/base"},
|
||||
{"/base", false, "a.org", "http://a.org/base"},
|
||||
{"http:", true, "a.org", "http://a.org"},
|
||||
{"https:", false, "a.org", "https://a.org"},
|
||||
{"http:/base", true, "a.org", "http://a.org/base"},
|
||||
{"https:/base", false, "a.org", "https://a.org/base"},
|
||||
{"https://b.org", true, "a.org", "https://b.org"},
|
||||
{"https://b.org", false, "a.org", "https://b.org"},
|
||||
{"http://b.org", true, "a.org", "http://b.org"},
|
||||
{"http://b.org", false, "a.org", "http://b.org"},
|
||||
}
|
||||
|
||||
dir := t.TempDir()
|
||||
@@ -75,13 +81,13 @@ func TestBase(t *testing.T) {
|
||||
if v.t {
|
||||
tcs = &tls.ConnectionState{}
|
||||
}
|
||||
base, err := groupBase(&http.Request{
|
||||
base, err := baseURL(&http.Request{
|
||||
TLS: tcs,
|
||||
Host: v.h,
|
||||
})
|
||||
if err != nil || base != v.res {
|
||||
if err != nil || base.String() != v.res {
|
||||
t.Errorf("Expected %v, got %v (%v)",
|
||||
v.res, base, err,
|
||||
v.res, base.String(), err,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user