// redirectedWarn writes a message redirected from a log.Logger at Warn level.
332502
func redirectedWarn(time string, caller string, message string) {
	logger.WithFields(map[string]interface{}{callerKey: caller, "time": time}).Warn(message)
}
459316
func WWWRedirect() Middleware {
	return func(h http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			if !strings.HasPrefix(r.Host, "www.") {
				http.Redirect(w, r, scheme(r)+"://www."+r.Host+r.RequestURI, http.StatusMovedPermanently)
				return
			}
			h.ServeHTTP(w, r)
		})
	}
}
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
			}
		}
	}
}
1302321
func (dl *ConsoleLogger) Warn(message interface{}, params ...interface{}) {
	dl.logger.Warnf(fmt.Sprintf("%s %s", caller(), fmt.Sprint(message)), params...)
}
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
}
164136
func (l *Logger) Warn(a ...interface{}) {
	l.logAll(optWarn, fmt.Sprint(a...))
}
449670
func NewRedirectFallbackWithLogger(r Redirect, l *log.Logger) (*RedirectFallback, error) {
	u, err := url.ParseRequestURI(r.URL)
	if err != nil {
		return nil, err
	}
	return &RedirectFallback{r: r, u: u, log: l}, nil
}
255196
func (entry *Entry) Warnf(format string, args ...interface{}) {
	if entry.lgEntry.Logger.Level >= lg.WarnLevel {
		entry.lgEntry.WithFields(entry.fields).Warnf(format, args...)
	}
}
932986
func (l *Log) Warnf(format string, args ...interface{}) {
	opts := getLoggerOpts(l.module, api.WARNING)
	if !opts.levelEnabled {
		return
	}
	if l.loadCustomLogger() {
		l.customLogger.Warnf(format, args...)
		return
	}
	l.logf(opts, api.WARNING, format, args...)
}
346813
func (l logger) Warnf(format string, args ...interface{}) {
	l.sourced().Warnf(format, args...)
}
91878
func (l *logger) Warnf(format string, v ...interface{}) {
	f := extractFields(&v)
	l.send(LevelWarn, 2, fmt.Sprintf(format, v...), f)
}
549331
func (l *Logger) Warnf(format string, v ...interface{}) {
	if l.getLevel() <= Warning {
		l.getHandler().Log(l.name, Warning, fmt.Sprintf(format, v...), 1)
	}
}
865778
func (self *HttpClient) checkRedirect(req *http.Request, via []*http.Request) error {
	if !self.FollowRedirects {
		// don't follow redirects if explicitly disabled
		return NoRedirect
	}

	if req.Method == "HEAD" && !self.HeadRedirects {
		// don't follow redirects on a HEAD request
		return NoRedirect
	}

	DebugLog(self.Verbose).Println("REDIRECT:", len(via), req.URL)
	if len(req.Cookies()) > 0 {
		DebugLog(self.Verbose).Println("COOKIES:", req.Cookies())
	}

	if len(via) >= 10 {
		return TooManyRedirects
	}

	if len(via) > 0 {
		last := via[len(via)-1]
		if len(last.Cookies()) > 0 {
			DebugLog(self.Verbose).Println("LAST COOKIES:", last.Cookies())
		}
	}

	// TODO: check for same host before adding headers
	self.addHeaders(req, nil)
	return nil
}
536282
func (r *Response) AddWarning(warning string) {
	if r.Warnings == nil {
		r.Warnings = make([]string, 0, 1)
	}
	r.Warnings = append(r.Warnings, warning)
}
470248
func (l *Logger) Warning(args ...interface{}) {
	l.logf(l.app, logLevelWarning, "", true, args...)
}
624067
func NonWWWRedirect() Middleware {
	return func(h http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			host := strings.TrimPrefix(r.Host, "www.")
			if len(host) < len(r.Host) {
				http.Redirect(w, r, scheme(r)+"://"+host+r.RequestURI, http.StatusMovedPermanently)
				return
			}
			h.ServeHTTP(w, r)
		})
	}
}
507330
func (c *ServerCommand) detectRedirect(detect physical.RedirectDetect,
	config *server.Config) (string, error) {
	// Get the hostname
	host, err := detect.DetectHostAddr()
	if err != nil {
		return "", err
	}

	// set [] for ipv6 addresses
	if strings.Contains(host, ":") && !strings.Contains(host, "]") {
		host = "[" + host + "]"
	}

	// Default the port and scheme
	scheme := "https"
	port := 8200

	// Attempt to detect overrides
	for _, list := range config.Listeners {
		// Only attempt TCP
		if list.Type != "tcp" {
			continue
		}

		// Check if TLS is disabled
		if val, ok := list.Config["tls_disable"]; ok {
			disable, err := parseutil.ParseBool(val)
			if err != nil {
				return "", errwrap.Wrapf("tls_disable: {{err}}", err)
			}

			if disable {
				scheme = "http"
			}
		}

		// Check for address override
		var addr string
		addrRaw, ok := list.Config["address"]
		if !ok {
			addr = "127.0.0.1:8200"
		} else {
			addr = addrRaw.(string)
		}

		// Check for localhost
		hostStr, portStr, err := net.SplitHostPort(addr)
		if err != nil {
			continue
		}
		if hostStr == "127.0.0.1" {
			host = hostStr
		}

		// Check for custom port
		listPort, err := strconv.Atoi(portStr)
		if err != nil {
			continue
		}
		port = listPort
	}

	// Build a URL
	url := &url.URL{
		Scheme: scheme,
		Host:   fmt.Sprintf("%s:%d", host, port),
	}

	// Return the URL string
	return url.String(), nil
}