summaryrefslogtreecommitdiffstats
path: root/api/context.go
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2015-09-22 12:12:50 -0700
committer=Corey Hulen <corey@hulen.com>2015-09-22 12:12:50 -0700
commit88e5a71e8c93b495cedaa07931a4f8052d9f12ed (patch)
tree603174fc3758d56b8a027b9e1fbe1a5d8690b3e6 /api/context.go
parent08a3acbb44b043b9bb56f9b96e91432352d06d1a (diff)
downloadchat-88e5a71e8c93b495cedaa07931a4f8052d9f12ed.tar.gz
chat-88e5a71e8c93b495cedaa07931a4f8052d9f12ed.tar.bz2
chat-88e5a71e8c93b495cedaa07931a4f8052d9f12ed.zip
Adding service settings to admin console
Diffstat (limited to 'api/context.go')
-rw-r--r--api/context.go38
1 files changed, 15 insertions, 23 deletions
diff --git a/api/context.go b/api/context.go
index c4684221d..9a276a1a1 100644
--- a/api/context.go
+++ b/api/context.go
@@ -107,21 +107,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
isTokenFromQueryString = true
}
- protocol := "http"
-
- // If the request came from the ELB then assume this is produciton
- // and redirect all http requests to https
- if utils.Cfg.ServiceSettings.UseSSL {
- forwardProto := r.Header.Get(model.HEADER_FORWARDED_PROTO)
- if forwardProto == "http" {
- l4g.Info("redirecting http request to https for %v", r.URL.Path)
- http.Redirect(w, r, "https://"+r.Host, http.StatusTemporaryRedirect)
- return
- } else {
- protocol = "https"
- }
- }
-
+ protocol := GetProtocol(r)
c.setSiteURL(protocol + "://" + r.Host)
w.Header().Set(model.HEADER_REQUEST_ID, c.RequestId)
@@ -209,6 +195,14 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
+func GetProtocol(r *http.Request) string {
+ if r.Header.Get(model.HEADER_FORWARDED_PROTO) == "https" {
+ return "https"
+ } else {
+ return "http"
+ }
+}
+
func (c *Context) LogAudit(extraInfo string) {
audit := &model.Audit{UserId: c.Session.UserId, IpAddress: c.IpAddress, Action: c.Path, ExtraInfo: extraInfo, SessionId: c.Session.Id}
if r := <-Srv.Store.Audit().Save(audit); r.Err != nil {
@@ -385,6 +379,11 @@ func (c *Context) GetSiteURL() string {
func GetIpAddress(r *http.Request) string {
address := r.Header.Get(model.HEADER_FORWARDED)
+
+ if len(address) == 0 {
+ address = r.Header.Get(model.HEADER_REAL_IP)
+ }
+
if len(address) == 0 {
address, _, _ = net.SplitHostPort(r.RemoteAddr)
}
@@ -458,14 +457,7 @@ func IsPrivateIpAddress(ipAddress string) bool {
func RenderWebError(err *model.AppError, w http.ResponseWriter, r *http.Request) {
- protocol := "http"
- if utils.Cfg.ServiceSettings.UseSSL {
- forwardProto := r.Header.Get(model.HEADER_FORWARDED_PROTO)
- if forwardProto != "http" {
- protocol = "https"
- }
- }
-
+ protocol := GetProtocol(r)
SiteURL := protocol + "://" + r.Host
m := make(map[string]string)