// Match returns true if the conn starts with an HTTP request.
Match returns true if the conn starts with an HTTP request.
// Match returns true if the conn starts with an HTTP request .
func (m MatchHTTP) Match(cx *layer4.Connection) (bool, error) {
	req, ok := cx.GetVar("http_request").(*http.Request)
	if !ok {
		var err error
		bufReader := bufio.NewReader(cx)
		req, err = http.ReadRequest(bufReader)
		if err != nil {
			return false, nil
		}
		err = m.handleHttp2WithPriorKnowledge(bufReader, req)
		if err != nil {
			return false, err
		}
		if connectionStates := l4tls.GetConnectionStates(cx); len(connectionStates) > 0 {
			req.TLS = connectionStates[len(connectionStates)-1]
		}
		req = caddyhttp.PrepareRequest(req, caddy.NewReplacer(), nil, nil)
		cx.SetVar("http_request", req)
		repl := cx.Context.Value(layer4.ReplacerCtxKey).(*caddy.Replacer)
		repl.Set("l4.http.host", req.Host)
	}
	return m.matcherSets.AnyMatch(req), nil
}
func ( m MatchHTTP ) Match ( cx * layer4 . Connection ) ( bool , error ) { req , ok := cx . GetVar ( " " ) . ( * http . Request ) if ! ok { var err error bufReader := bufio . NewReader ( cx ) req , err = http . ReadRequest ( bufReader ) if err != nil { return false , nil } err = m . handleHttp2WithPriorKnowledge ( bufReader , req ) if err != nil { return false , err } if connectionStates := l4tls . GetConnectionStates ( cx ) ; len ( connectionStates ) > 0 { req . TLS = connectionStates [ len ( connectionStates ) - 1 ] } req = caddyhttp . PrepareRequest ( req , caddy . NewReplacer ( ) , nil , nil ) cx . SetVar ( " " , req ) repl := cx . Context . Value ( layer4 . ReplacerCtxKey ) . ( * caddy . Replacer ) repl . Set ( " " , req . Host ) } return m . matcherSets . AnyMatch ( req ) , nil }
Match returns true if the conn starts with an HTTP request.
Match returns true if the conn starts with an HTTP request .
// TODO: do we need a more standardized way to amortize matchers? or at least to remember decoded results from previous matchers? // TODO: find a way to distinguish actual errors from mismatches // check if req is a http2 request made with prior knowledge and if so parse it // if the tls handler was used before fill in the TLS field of the request // with the last aka innermost tls connection state // in order to use request matchers, we have to populate the request context // remember this for future use // also add values to the replacer (TODO: we could probably find a way to use the http app's replacer values) // we have a valid HTTP request, so we can drill down further if there are // any more matchers configured