diff --git a/extractor.go b/extractor.go index 25b0f4b..9059e1e 100644 --- a/extractor.go +++ b/extractor.go @@ -48,6 +48,8 @@ func createExtractors(lookups, authScheme string) ([]ValuesExtractor, error) { switch parts[0] { case "query": extractors = append(extractors, valuesFromQuery(parts[1])) + case "param": + extractors = append(extractors, valuesFromParam(parts[1])) case "cookie": extractors = append(extractors, valuesFromCookie(parts[1])) case "form": @@ -121,6 +123,22 @@ func valuesFromQuery(param string) ValuesExtractor { } } +// valuesFromParam returns a function that extracts values from the url param string. +func valuesFromParam(param string) ValuesExtractor { + return func(ctx *http.RequestCtx) ([][]byte, error) { + if !ctx.PostArgs().Has(param) { + return nil, errParamExtractorValueMissing + } + + result := ctx.PostArgs().PeekMulti(param) + if len(result) > extractorLimit-1 { + result = result[:extractorLimit] + } + + return result, nil + } +} + // valuesFromCookie returns a function that extracts values from the named cookie. func valuesFromCookie(name string) ValuesExtractor { return func(ctx *http.RequestCtx) ([][]byte, error) {