-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
try to use referer when the path is not forced #41
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,19 +94,33 @@ func handler(w http.ResponseWriter, r *http.Request) { | |
c := appengine.NewContext(r) | ||
params := strings.SplitN(strings.Trim(r.URL.Path, "/"), "/", 2) | ||
query, _ := url.ParseQuery(r.URL.RawQuery) | ||
refOrg := r.Header.Get("Referer") | ||
|
||
// / -> redirect | ||
if len(params[0]) == 0 { | ||
http.Redirect(w, r, "https://github.com/igrigorik/ga-beacon", http.StatusFound) | ||
return | ||
} | ||
|
||
// activate referrer path if ?useReferer is used and if referer exists | ||
if _, ok := query["useReferer"]; ok { | ||
if len(refOrg) != 0 { | ||
referer := strings.Replace(strings.Replace(refOrg, "http://", "", 1), "https://", "", 1); | ||
if len(referer) != 0 { | ||
// if the useReferer is present and the referer information exists | ||
// the path is ignored and the beacon referer information is used instead. | ||
params = strings.SplitN(strings.Trim(r.URL.Path, "/") + "/" + referer, "/", 2) | ||
} | ||
} | ||
} | ||
// /account -> account template | ||
if len(params) == 1 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is only invoked if you don't pass in the account name + path.. I'm not sure that's what you're after? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, when len(params) == 1 is because the path only contains the account. The account is still required, although we can probably set a default one in some configuration file if non is passed. |
||
templateParams := struct { | ||
Account string | ||
Referer string | ||
}{ | ||
Account: params[0], | ||
Referer: refOrg, | ||
} | ||
if err := pageTemplate.ExecuteTemplate(w, "page.html", templateParams); err != nil { | ||
http.Error(w, "could not show account page", 500) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth documenting what will happen when you specify both.. a path and enable useReferer?