Skip to content

Allow excluding traffic by matching headers - #5

Merged
pboos merged 1 commit into
mainfrom
feature/allow-excluding-traffic-by-headers
May 26, 2023
Merged

Allow excluding traffic by matching headers#5
pboos merged 1 commit into
mainfrom
feature/allow-excluding-traffic-by-headers

Conversation

@pboos

@pboos pboos commented May 25, 2023

Copy link
Copy Markdown
Contributor

Exclude requests from validation by specifying headers that match a specific pattern.

This allows to exclude requests from bots that are identifiable through headers.

This can be configured through application.properties like the following:

openapi.validation.excluded-headers[0]=User-Agent: .*(bingbot|googlebot).*
openapi.validation.excluded-headers[1]=x-is-bot: true

@pboos
pboos requested review from a team and eleonoraborghi May 25, 2023 15:47
private boolean isRequestExcludedByHeader(RequestMetaData request) {
return excludedHeaders.stream().anyMatch(excludedHeader -> {
var headerValue = request.getHeaders().get(excludedHeader.headerName());
return headerValue != null && excludedHeader.headerValuePattern().matcher(headerValue).matches();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, is it possible to have headerValue == null IYO?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is possible because we go through the list of headers one wants to exclude like x-is-bot. Then request.getHeaders().get("x-is-bot"); can return null if there is no such header sent in the request.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2023-05-26 at 08 48 59

@eleonoraborghi eleonoraborghi left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐑 it

@pboos
pboos merged commit 63a0ceb into main May 26, 2023
@pboos
pboos deleted the feature/allow-excluding-traffic-by-headers branch June 9, 2023 08:57
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

Successfully merging this pull request may close these issues.

2 participants