-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
relay icons as files in the ./stuff folder.
- Loading branch information
Showing
5 changed files
with
65 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
func getServiceBaseURL(r *http.Request) string { | ||
if s.ServiceURL != "" { | ||
return s.ServiceURL | ||
} | ||
host := r.Header.Get("X-Forwarded-Host") | ||
if host == "" { | ||
host = r.Host | ||
} | ||
proto := r.Header.Get("X-Forwarded-Proto") | ||
if proto == "" { | ||
if host == "localhost" { | ||
proto = "http" | ||
} else if strings.Index(host, ":") != -1 { | ||
// has a port number | ||
proto = "http" | ||
} else if _, err := strconv.Atoi(strings.ReplaceAll(host, ".", "")); err == nil { | ||
// it's a naked IP | ||
proto = "http" | ||
} else { | ||
proto = "https" | ||
} | ||
} | ||
return proto + "://" + host | ||
} | ||
|
||
func getIconURL(r *http.Request) string { | ||
for _, possibleIcon := range []string{"icon.png", "icon.jpg", "icon.jpeg", "icon.gif"} { | ||
if _, err := os.Stat(filepath.Join(s.CustomDirectory, possibleIcon)); err == nil { | ||
return getServiceBaseURL(r) + "/" + possibleIcon | ||
} | ||
} | ||
return "" | ||
} |