Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: rate limit on HTTP query parameter #161

Open
negz opened this issue Sep 29, 2018 · 1 comment
Open

Feature request: rate limit on HTTP query parameter #161

negz opened this issue Sep 29, 2018 · 1 comment

Comments

@negz
Copy link

negz commented Sep 29, 2018

Hello,

At Planet Labs we're considering replacing an internally developed edge router with Traefik. Our edge router is very similar to Traefik, including its use of oxy. We have one rate limiting use case that's not supported by oxy out of the box; we'd like to rate limit on HTTP URL query parameter. We need to rate limit on query parameters because some of our legacy clients provide their API key as a query param.

We'd effectively want to add the following:

// NewExtractor creates a new SourceExtractor
func NewExtractor(variable string) (SourceExtractor, error) {
	if variable == "client.ip" {
		return ExtractorFunc(extractClientIP), nil
	}
	if variable == "request.host" {
		return ExtractorFunc(extractHost), nil
	}
	if strings.HasPrefix(variable, "request.header.") {
		header := strings.TrimPrefix(variable, "request.header.")
		if len(header) == 0 {
			return nil, fmt.Errorf("wrong header: %s", header)
		}
		return makeHeaderExtractor(header), nil
	}
	if strings.HasPrefix(variable, "request.queryparam.") {
		param := strings.TrimPrefix(variable, "request.queryparam.")
		if len(param) == 0 {
			return nil, fmt.Errorf("wrong param: %s", header)
		}
		return makeQueryParamExtractor(param), nil
	}
	return nil, fmt.Errorf("unsupported limiting variable: '%s'", variable)
}

func makeQueryParamExtractor(param string) SourceExtractor {
	return ExtractorFunc(func(req *http.Request) (string, int64, error) {
		return req.URL.Query().Get(param), 1, nil
	})
}

Would you accept a PR with such functionality?

@negz
Copy link
Author

negz commented Nov 8, 2018

Ping. Any thoughts on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant