Skip to content

Performance improvement in RequestMappingInfo #22598

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class ReadOnlyHttpHeaders extends HttpHeaders {
@Nullable
private MediaType cachedContentType;

@Nullable
private MediaType cachedAccept;

ReadOnlyHttpHeaders(HttpHeaders headers) {
super(headers.headers);
}
Expand All @@ -56,6 +59,18 @@ public MediaType getContentType() {
}
}

@Override
public List<MediaType> getAccept() {
if (this.cachedAccept != null) {
return this.cachedAccept;
}
else {
List<MediaType> accept = super.getAccept();
this.cachedAccept = accept;
return accept;
}
}

@Override
public List<String> get(Object key) {
List<String> values = this.headers.get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,29 @@ else if (this.name != null) {
@Nullable
public RequestMappingInfo getMatchingCondition(ServerWebExchange exchange) {
RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(exchange);
if (methods == null) {
return null;
}
ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(exchange);
if (params == null) {
return null;
}
HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(exchange);
ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(exchange);
ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(exchange);

if (methods == null || params == null || headers == null || consumes == null || produces == null) {
if (headers == null) {
return null;
}

PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(exchange);
if (patterns == null) {
return null;
}

ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(exchange);
if (consumes == null) {
return null;
}
ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(exchange);
if (produces == null) {
return null;
}
RequestConditionHolder custom = this.customConditionHolder.getMatchingCondition(exchange);
if (custom == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,29 @@ else if (this.name != null) {
@Nullable
public RequestMappingInfo getMatchingCondition(HttpServletRequest request) {
RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(request);
if (methods == null) {
return null;
}
ParamsRequestCondition params = this.paramsCondition.getMatchingCondition(request);
if (params == null) {
return null;
}
HeadersRequestCondition headers = this.headersCondition.getMatchingCondition(request);
ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(request);
ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(request);

if (methods == null || params == null || headers == null || consumes == null || produces == null) {
if (headers == null) {
return null;
}

PatternsRequestCondition patterns = this.patternsCondition.getMatchingCondition(request);
if (patterns == null) {
return null;
}

ConsumesRequestCondition consumes = this.consumesCondition.getMatchingCondition(request);
if (consumes == null) {
return null;
}
ProducesRequestCondition produces = this.producesCondition.getMatchingCondition(request);
if (produces == null) {
return null;
}
RequestConditionHolder custom = this.customConditionHolder.getMatchingCondition(request);
if (custom == null) {
return null;
Expand Down