Ejemplo n.º 1
0
// Redirect back to a return URL, if specified; otherwise, redirect to
// defaultURL.
func ReturnRedirect(req *http.Request, statusCode int, defaultURL string) {
	ak := opts.VariantSecretKey("redirect")
	r := req.FormValue("r")

	if r != "" && webac.VerifyFor("redirect/"+r, req.FormValue("rac"), ak) {
		if _, err := url.Parse(r); err == nil {
			defaultURL = r
		}
	}

	miscctx.RedirectTo(req, statusCode, defaultURL)
}
Ejemplo n.º 2
0
func (cfg *Config) redirectCanonicalize(req *http.Request, transformFunc func(u *url.URL)) {
	newURL, err := url.Parse(cfg.BaseURL)
	if err != nil {
		newURL = &url.URL{}
		newURL.Host = req.Host
	}
	newURL.Path = req.URL.Path
	newURL.RawQuery = req.URL.RawQuery
	transformFunc(newURL)

	miscctx.RedirectTo(req, 308, newURL.String())
}
Ejemplo n.º 3
0
// Redirect to a given URL with the given status code, such that the user agent
// can eventually be redirected back to the current URL, unless a return URL
// has already been provided in the current request, in which case that return
// URL is used.
func RedirectWithReturn(req *http.Request, statusCode int, targetURL string) {
	ak := opts.VariantSecretKey("redirect")
	ustr := req.URL.String()

	r, rac := req.FormValue("r"), req.FormValue("rac")
	if r == "" || !webac.VerifyFor("redirect/"+r, rac, ak) {
		r = ustr
		rac = webac.NewFor("redirect/"+r, ak)
	}

	tgt, err := req.URL.Parse(targetURL)
	if err == nil {
		q := tgt.Query()
		q.Set("r", r)
		q.Set("rac", rac)
		tgt.RawQuery = q.Encode()
		targetURL = tgt.String()
	}

	miscctx.RedirectTo(req, statusCode, targetURL)
}