// issueRedirect returns whether the request should be redirected to the
// issues tracker, and the url for that redirection if yes, the empty
// string otherwise.
196909
func issueRedirect(urlPath string) (string, bool) {
	m := issueNum.FindStringSubmatch(urlPath)
	if m == nil {
		return "", false
	}
	issueNumber := strings.TrimPrefix(m[1], "/")
	suffix := ""
	if issueNumber != "" {
		suffix = "/" + issueNumber
	}
	return "https://github.com/perkeep/perkeep/issues" + suffix, true
}
1054366
func IsRedirectError(err error) bool {
	if err == nil {
		return false
	}

	// TODO: does not work?
	if getErrorCode(err) == ERR_REDIRECT_POLICY {
		return true
	}

	// TODO: make it reliable
	if strings.Contains(err.Error(), "redirect") {
		return true
	}

	return false
}
1205103
func (h *HTTPBin) AbsoluteRedirect(w http.ResponseWriter, r *http.Request) {
	doRedirect(w, r, false)
}
1328725
func (r *Router) Redirect(w http.ResponseWriter, req *http.Request, path string, code int) {
	http.Redirect(w, req, r.prefix+path, code)
}
1006610
func getRedirectPostRawQuery(objInfo ObjectInfo) string {
	redirectValues := make(url.Values)
	redirectValues.Set("bucket", objInfo.Bucket)
	redirectValues.Set("key", objInfo.Name)
	redirectValues.Set("etag", "\""+objInfo.ETag+"\"")
	return redirectValues.Encode()
}
1207988
func (self *OAuth1Mixin) Redirect(w http.ResponseWriter, r *http.Request) {
	if err := self.AuthorizeRedirect(w, r, self.Consumer.AuthorizationURL); err != nil {
		println("Error redirecting to authorization endpoint: " + err.Error())
	}
}
861010
func Redirects(n int) func(*Attacker) {
	return func(a *Attacker) {
		a.redirects = n
		a.client.CheckRedirect = func(_ *http.Request, via []*http.Request) error {
			switch {
			case n == NoFollow:
				return http.ErrUseLastResponse
			case n < len(via):
				return fmt.Errorf("stopped after %d redirects", n)
			default:
				return nil
			}
		}
	}
}
1053911
func (m *Mixpanel) RedirectURL(distinctID, event, uri string, props Properties) (string, error) {
	if distinctID != "" {
		props["$distinct_id"] = distinctID
	}
	props["$token"] = m.Token
	props["mp_lib"] = library

	data := map[string]interface{}{"event": event, "properties": props}
	b, err := json.Marshal(data)
	if err != nil {
		return "", err
	}

	params := map[string]string{
		"data":     base64.StdEncoding.EncodeToString(b),
		"redirect": uri,
	}
	query := url.Values{}
	for k, v := range params {
		query[k] = []string{v}
	}
	return fmt.Sprintf("%s/%s?%s", m.BaseUrl, "track", query.Encode()), nil
}
103592
func (c *Context) Redirect(code int, location string) error {
	if (code < 300 || code > 308) && code != 201 {
		return fmt.Errorf("Cannot redirect with status code %d", code)
	}
	http.Redirect(c.Writer, c.Request, location, code)
	return nil
}
108109
func (ctxt *Context) Redirect(url string) {
	http.Redirect(ctxt, ctxt.Request, url, http.StatusFound)
}
1201984
func (self *GithubProvider) Redirect(w http.ResponseWriter, r *http.Request) {
	self.OAuth2Mixin.AuthorizeRedirect(w, r, self.Scope)
}
82225
func SafeRedirect(w http.ResponseWriter, r *http.Request, redirectURL string) error {
	parsedURL, err := url.Parse(redirectURL)
	if err != nil {
		return trace.Wrap(err)
	}
	http.Redirect(w, r, parsedURL.RequestURI(), http.StatusFound)
	return nil
}
910045
func (wfe *WebFrontEndImpl) Issuer(ctx context.Context, logEvent *web.RequestEvent, response http.ResponseWriter, request *http.Request) {
	// TODO Content negotiation
	response.Header().Set("Content-Type", "application/pkix-cert")
	response.WriteHeader(http.StatusOK)
	if _, err := response.Write(wfe.IssuerCert); err != nil {
		wfe.log.Warningf("Could not write response: %s", err)
	}
}
642644
func (c *Context) RawRedirect(location string, status ...int) {
	c.Context.Redirect(location, status...)
}
905595
func Redirect(w http.ResponseWriter, r *http.Request, newPath string, statusCode int) {
	if q := r.URL.RawQuery; q != "" {
		newPath += "?" + q
	}
	http.Redirect(w, r, newPath, statusCode)
}
1110264
func (k *Key) Issuer() string {
	q := k.url.Query()

	issuer := q.Get("issuer")

	if issuer != "" {
		return issuer
	}

	p := strings.TrimPrefix(k.url.Path, "/")
	i := strings.Index(p, ":")

	if i == -1 {
		return ""
	}

	return p[:i]
}
848780
func (d *Daemon) UpdateProxyRedirect(e *endpoint.Endpoint, l4 *policy.L4Filter, proxyWaitGroup *completion.WaitGroup) (uint16, error, revert.FinalizeFunc, revert.RevertFunc) {
	if d.l7Proxy == nil {
		return 0, fmt.Errorf("can't redirect, proxy disabled"), nil, nil
	}

	port, err, finalizeFunc, revertFunc := d.l7Proxy.CreateOrUpdateRedirect(l4, e.ProxyID(l4), e, proxyWaitGroup)
	if err != nil {
		return 0, err, nil, nil
	}

	return port, nil, finalizeFunc, revertFunc
}