Skip to content

Commit

Permalink
Initialize RequestPath on demand
Browse files Browse the repository at this point in the history
Closes gh-33227
  • Loading branch information
rstoyanchev committed Jul 17, 2024
1 parent 30a64d6 commit b9509d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,7 +50,11 @@ public abstract class AbstractServerHttpRequest implements ServerHttpRequest {

private final URI uri;

private final RequestPath path;
@Nullable
private final String contextPath;

@Nullable
private RequestPath path;

private final HttpHeaders headers;

Expand Down Expand Up @@ -92,7 +96,7 @@ public AbstractServerHttpRequest(HttpMethod method, URI uri, @Nullable String co

this.method = method;
this.uri = uri;
this.path = RequestPath.parse(uri, contextPath);
this.contextPath = contextPath;
this.headers = HttpHeaders.readOnlyHttpHeaders(headers);
}

Expand Down Expand Up @@ -140,6 +144,9 @@ public Map<String, Object> getAttributes() {

@Override
public RequestPath getPath() {
if (this.path == null) {
this.path = RequestPath.parse(this.uri, this.contextPath);
}
return this.path;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void mutateWithExistingContextPath() throws Exception {
void mutateContextPathWithoutUpdatingPathShouldFail() throws Exception {
ServerHttpRequest request = createRequest("/context/path", "/context");

assertThatThrownBy(() -> request.mutate().contextPath("/fail").build())
assertThatThrownBy(() -> request.mutate().contextPath("/fail").build().getPath())
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Invalid contextPath '/fail': must match the start of requestPath: '/context/path'");
}
Expand Down

0 comments on commit b9509d3

Please sign in to comment.