// Rewrite rewrites the internal location of the current request.
501990
func (s *SimpleRule) Rewrite(fs http.FileSystem, r *http.Request) Result {

	// attempt rewrite
	return To(fs, r, s.To, newReplacer(r))
}
929079
func (c Conn) CloseWrite() error {
	if cw, ok := c.Wire.(interface {
		CloseWrite() error
	}); ok {
		return cw.CloseWrite()
	}
	return errors.New("pinned: underlying connection does not support CloseWrite")
}
1366641
func (ctx *Context) Redirect(url string) {
	ctx.SetHeader("Location", url)
	ctx.SendStatus(302)
}
243090
func (ctx *Context) Redirect(url string, status ...int) {
	s := http.StatusFound
	if len(status) > 0 {
		s = status[0]
	}
	http.Redirect(ctx.ResponseWriter, ctx.Req(), url, s)
}
1161794
func Rewrite(rules map[string]string) echo.MiddlewareFunc {
	c := DefaultRewriteConfig
	c.Rules = rules
	return RewriteWithConfig(c)
}
1072171
func RouteOriginalURL(r *http.Request) {
	// RawPath is only set if the url had special characters or was canonized.
	if len(r.URL.RawPath) > 0 {
		plog.WithFields(log.Fields{
			"Path":    r.URL.Path,
			"RawPath": r.URL.RawPath,
		}).Debug("handler: rewriting url")
		r.URL.Opaque = r.URL.RawPath
	}
}
364374
func (ctx *Context) Redirect(status int, url_ string) {
	ctx.ResponseWriter.Header().Set("Location", url_)
	ctx.ResponseWriter.WriteHeader(status)
	ctx.ResponseWriter.Write([]byte("Redirecting to: " + url_))
}
421917
func (rule *substringTtlRule) Rewrite(ctx context.Context, state request.Request) Result {
	if strings.Contains(state.Name(), rule.Substring) {
		return RewriteDone
	}
	return RewriteIgnored
}
327607
func (rule *suffixTtlRule) Rewrite(ctx context.Context, state request.Request) Result {
	if strings.HasSuffix(state.Name(), rule.Suffix) {
		return RewriteDone
	}
	return RewriteIgnored
}
440379
func (rw Rewrite) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
	if rule := httpserver.ConfigSelector(rw.Rules).Select(r); rule != nil {
		rule.(Rule).Rewrite(rw.FileSys, r)
	}

	return rw.Next.ServeHTTP(w, r)
}
1267072
func RewriteExpr(expr Expr, fn func(Expr) Expr) Expr {
	switch e := expr.(type) {
	case *BinaryExpr:
		e.LHS = RewriteExpr(e.LHS, fn)
		e.RHS = RewriteExpr(e.RHS, fn)
		if e.LHS != nil && e.RHS == nil {
			expr = e.LHS
		} else if e.RHS != nil && e.LHS == nil {
			expr = e.RHS
		} else if e.LHS == nil && e.RHS == nil {
			return nil
		}

	case *ParenExpr:
		e.Expr = RewriteExpr(e.Expr, fn)
		if e.Expr == nil {
			return nil
		}

	case *Call:
		for i, expr := range e.Args {
			e.Args[i] = RewriteExpr(expr, fn)
		}
	}

	return fn(expr)
}
149359
func (rule *typeRule) Rewrite(w dns.ResponseWriter, r *dns.Msg) Result {
	if rule.fromType > 0 && rule.toType > 0 {
		if r.Question[0].Qtype == rule.fromType {
			r.Question[0].Qtype = rule.toType
			return RewriteDone
		}
	}
	return RewriteIgnored
}
480763
func (rule PushDownRangeRule) Rewrite(node plan.Node) (plan.Node, bool, error) {
	fromNode := node.Predecessors()[0]
	fromSpec := fromNode.ProcedureSpec().(*FromProcedureSpec)

	rangeSpec := node.ProcedureSpec().(*universe.RangeProcedureSpec)
	return plan.CreatePhysicalNode("ReadRange", &ReadRangePhysSpec{
		Bucket:   fromSpec.Bucket,
		BucketID: fromSpec.BucketID,
		Bounds:   rangeSpec.Bounds,
	}), true, nil
}
731469
func (r *Response) Redirect(status int, url_ string) {
	r.ResponseWriter.Header().Set("Location", url_)
	r.Abort(status, "Redirecting to: "+url_)
}
742002
func (rule *edns0VariableRule) Rewrite(ctx context.Context, state request.Request) Result {
	data, err := rule.ruleData(ctx, state)
	if err != nil || data == nil {
		return RewriteIgnored
	}

	o := setupEdns0Opt(state.Req)
	for _, s := range o.Option {
		if e, ok := s.(*dns.EDNS0_LOCAL); ok {
			if rule.code == e.Code {
				if rule.action == Replace || rule.action == Set {
					e.Data = data
					return RewriteDone
				}
				return RewriteIgnored
			}
		}
	}

	// add option if not found
	if rule.action == Append || rule.action == Set {
		o.Option = append(o.Option, &dns.EDNS0_LOCAL{Code: rule.code, Data: data})
		return RewriteDone
	}

	return RewriteIgnored
}
748912
func (this *Response) Redirect(uri string, s ...int) {

	req := this.req
	isHead := req.Method == "HEAD"

	this.StatusCode = 302

	// If we were given a status, us it.
	if len(s) == 1 {
		this.StatusCode = s[0]
	}

	this.Location(uri)

	uri = this.Get("Location")

	var body string

	this.Format(map[string]func(){
		"text/plain": func() {
			body = httphelp.StatusCodes[this.StatusCode] + ". Redirecting to " + uri
		},
		"text/html": func() {
			u := html.EscapeString(uri)
			body = "<p>" + httphelp.StatusCodes[this.StatusCode] + ". Redirecting to <a href=\"" + u + "\">" + u + "</a></p>"
		},
		"default": func() {
			body = ""
		},
	})

	this.Set("Content-Length", fmt.Sprint(len(body)))

	if isHead {
		body = ""
	}

	this.End(body)
}
782635
func Rewriter(fs VFS, rewriter func(oldPath string) (newPath string)) VFS {
	if rewriter == nil {
		return fs
	}
	return &rewriterFileSystem{fs: fs, rewriter: rewriter}
}