/*
Match runs the Pat pattern on the given request, returning a non-nil context if
the request matches the request.

This function satisfies goji.Pattern.
*/
481332
func (p *Pattern) Match(ctx context.Context, r *http.Request) context.Context {
	if p.methods != nil {
		if _, ok := p.methods[r.Method]; !ok {
			return nil
		}
	}

	// Check Path
	path := pattern.Path(ctx)
	var scratch []string
	if p.wildcard {
		scratch = make([]string, len(p.pats)+1)
	} else if len(p.pats) > 0 {
		scratch = make([]string, len(p.pats))
	}

	for i := range p.pats {
		sli := p.literals[i]
		if !strings.HasPrefix(path, sli) {
			return nil
		}
		path = path[len(sli):]

		m := 0
		bc := p.breaks[i]
		for ; m < len(path); m++ {
			if path[m] == bc || path[m] == '/' {
				break
			}
		}
		if m == 0 {
			// Empty strings are not matches, otherwise routes like
			// "/:foo" would match the path "/"
			return nil
		}
		scratch[i] = path[:m]
		path = path[m:]
	}

	// There's exactly one more literal than pat.
	tail := p.literals[len(p.pats)]
	if p.wildcard {
		if !strings.HasPrefix(path, tail) {
			return nil
		}
		scratch[len(p.pats)] = path[len(tail)-1:]
	} else if path != tail {
		return nil
	}

	for i := range p.pats {
		var err error
		scratch[i], err = unescape(scratch[i])
		if err != nil {
			// If we encounter an encoding error here, there's
			// really not much we can do about it with our current
			// API, and I'm not really interested in supporting
			// clients that misencode URLs anyways.
			return nil
		}
	}

	return &match{ctx, p, scratch}
}
1335617
func (router *router) match(req *Request) (*Route, error) {
	// todo: consider using goroutines for searching for route

	method := req.Method
	path := req.URL.Path

	for _, route := range router.routes[method] {
		params, err := route.regex.Match(path)

		if err == nil {
			req.Params = params
			return &route, nil
		}
	}

	return nil, errors.New("[" + req.Method + "] handler for route " + path + " not found")
}
1233386
func (r *ssrf) Match(n ast.Node, c *gosec.Context) (*gosec.Issue, error) {
	// Call expression is using http package directly
	if node := r.ContainsCallExpr(n, c, false); node != nil {
		if r.ResolveVar(node, c) {
			return gosec.NewIssue(c, n, r.ID(), r.What, r.Severity, r.Confidence), nil
		}
	}
	return nil, nil
}
712225
func (m MatcherFunc) Match(r *http.Request, match *RouteMatch) bool {
	return m(r, match)
}
565432
func (r *routeRegexp) Match(req *http.Request, match *RouteMatch) bool {
	if r.regexpType != regexpTypeHost {
		if r.regexpType == regexpTypeQuery {
			return r.matchQueryString(req)
		}
		path := req.URL.Path
		if r.options.useEncodedPath {
			path = req.URL.EscapedPath()
		}
		return r.regexp.MatchString(path)
	}

	return r.regexp.MatchString(getHost(req))
}
1273355
func match(r *http.Request, sess *sessions.Session, refresh bool) bool {

	valid := false
	path := r.URL.Path

	if SingleToken {
		path = "/"
	}

	// If tokens exists
	if token, ok := sess.Values[TokenName]; ok {

		// Token submitted via POST
		sentToken := r.FormValue(TokenName)

		// Detect the content type
		switch r.Header.Get("Content-Type") {
		case "application/x-www-form-urlencoded":
			sentToken = r.FormValue(TokenName)
			break
		case "application/json":
			// Prevents throwing an error if nil
			b := bytes.NewBuffer(make([]byte, 0))
			body_reader := io.TeeReader(r.Body, b)
			if r.Body == nil {
				break
			}
			var t interface{}
			decoder := json.NewDecoder(body_reader)
			err := decoder.Decode(&t)

			// If the response is JSON
			if err == nil {
				vals := t.(map[string]interface{})
				// Update the token value
				sentToken = fmt.Sprintf("%v", vals[TokenName])
			}
			r.Body = ioutil.NopCloser(b)
			break
		}

		// If token is empty in the form, it is not valid
		if sentToken == "" {
			valid = false
		} else {
			// Check token against same page URL
			if sentToken == token.(StringMap)[path] {
				valid = true
			} else {
				// Extract the relative referer path
				offset := strings.Index(r.Referer(), r.Host) + len(r.Host)

				// Make sure no errors can be thrown
				if offset != 0 && offset < len(r.Referer()) {
					// Check token against previous page
					if sentToken == token.(StringMap)[r.Referer()[offset:]] {
						valid = true
					}
				}

			}
		}

		if refresh {
			delete(token.(StringMap), path)
		}
	}

	return valid
}
238877
func (s *SimpleRule) Match(r *http.Request) bool {
	matches := regexpMatches(s.Regexp, "/", r.URL.Path)
	if s.Negate {
		return len(matches) == 0
	}
	return len(matches) > 0
}
761411
func (self *Constraint) Match(version string) bool {
	return Compare(version, self.version, self.operator)
}
565999
func (l *Lexer) match(matchTo string, skip int) bool {

	//u.Debugf("match(%q)  peek:%q ", matchTo, l.PeekWord())
	for _, matchRune := range matchTo {
		//u.Debugf("match rune? %v", string(matchRune))
		if skip > 0 {
			skip--
			continue
		}

		nr := l.Next()
		//u.Debugf("rune=%s n=%s   %v  %v", string(matchRune), string(nr), matchRune != nr, unicode.ToLower(nr) != matchRune)
		if matchRune != nr && unicode.ToLower(nr) != matchRune {
			//u.Debugf("setting done = false?, ie did not match")
			return false
		}
	}
	if l.IsEnd() {
		return true
	}
	// If we finished looking for the match word, and the next item is not
	// whitespace, it means we failed
	if !isWhiteSpace(l.Peek()) {
		return false
	}
	//u.Debugf("Found match():  %v", matchTo)
	return true
}
660280
func (c Context) PathMatches(pattern string) bool {
	return Path(c.Req.URL.Path).Matches(pattern)
}
1025368
func (s *Intention) Match(
	args *structs.IntentionQueryRequest,
	reply *structs.IndexedIntentionMatches) error {
	// Forward if necessary
	if done, err := s.srv.forward("Intention.Match", args, args, reply); done {
		return err
	}

	// Get the ACL token for the request for the checks below.
	rule, err := s.srv.ResolveToken(args.Token)
	if err != nil {
		return err
	}

	if rule != nil {
		// We go through each entry and test the destination to check if it
		// matches.
		for _, entry := range args.Match.Entries {
			if prefix := entry.Name; prefix != "" && !rule.IntentionRead(prefix) {
				s.srv.logger.Printf("[WARN] consul.intention: Operation on intention prefix '%s' denied due to ACLs", prefix)
				return acl.ErrPermissionDenied
			}
		}
	}

	return s.srv.blockingQuery(
		&args.QueryOptions,
		&reply.QueryMeta,
		func(ws memdb.WatchSet, state *state.Store) error {
			index, matches, err := state.IntentionMatch(ws, args.Match)
			if err != nil {
				return err
			}

			reply.Index = index
			reply.Matches = matches
			return nil
		},
	)
}
1060351
func (w *Wildmatch) Match(t string) bool {
	dirs, ok := w.consume(t, MatchOpts{})
	if !ok {
		return false
	}
	return len(dirs) == 0
}
643246
func (p Principal) Match(principal string) bool {
	for _, pattern := range p.AWS.ToSlice() {
		if wildcard.MatchSimple(pattern, principal) {
			return true
		}
	}

	return false
}
367733
func Match(method string, route string, handler interface{}) {
	mainServer.addRoute(route, method, handler)
}
351104
func (r *Route) Match(req *http.Request) bool {
	ok, _ := r.matchAndParse(req)
	return ok
}
736573
func (pg *GoEvtxMap) RegexMatch(path *GoEvtxPath, pattern *regexp.Regexp) bool {
	s, err := pg.GetString(path)
	if err != nil {
		return false
	}
	return pattern.MatchString(s)
}
1194154
func Match(ctx context.Context, expectedVersion string) bool {
	return If(GetVersion(ctx), expectedVersion)
}