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

Add assert null validations for DefaultServerResponseBuilder #30157

Closed
wants to merge 2 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 @@ -91,6 +91,7 @@ public DefaultServerResponseBuilder(HttpStatusCode status) {

@Override
public ServerResponse.BodyBuilder header(String headerName, String... headerValues) {
Assert.notNull(headerName, "HeaderName must not be null");
for (String headerValue : headerValues) {
this.headers.add(headerName, headerValue);
}
Expand All @@ -99,6 +100,7 @@ public ServerResponse.BodyBuilder header(String headerName, String... headerValu

@Override
public ServerResponse.BodyBuilder headers(Consumer<HttpHeaders> headersConsumer) {
Assert.notNull(headersConsumer, "HeadersConsumer must not be null");
headersConsumer.accept(this.headers);
return this;
}
Expand All @@ -112,18 +114,21 @@ public ServerResponse.BodyBuilder cookie(ResponseCookie cookie) {

@Override
public ServerResponse.BodyBuilder cookies(Consumer<MultiValueMap<String, ResponseCookie>> cookiesConsumer) {
Assert.notNull(cookiesConsumer, "CookiesConsumer must not be null");
cookiesConsumer.accept(this.cookies);
return this;
}

@Override
public ServerResponse.BodyBuilder allow(HttpMethod... allowedMethods) {
Assert.notNull(allowedMethods, "Http allowedMethod must not be null");
this.headers.setAllow(new LinkedHashSet<>(Arrays.asList(allowedMethods)));
return this;
}

@Override
public ServerResponse.BodyBuilder allow(Set<HttpMethod> allowedMethods) {
Assert.notNull(allowedMethods, "Http allowedMethod must not be null");
this.headers.setAllow(allowedMethods);
return this;
}
Expand All @@ -142,6 +147,7 @@ public ServerResponse.BodyBuilder contentType(MediaType contentType) {

@Override
public ServerResponse.BodyBuilder eTag(String etag) {
Assert.notNull(etag, "etag must not be null");
if (!etag.startsWith("\"") && !etag.startsWith("W/\"")) {
etag = "\"" + etag;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public DefaultServerResponseBuilder(HttpStatusCode status) {

@Override
public ServerResponse.BodyBuilder header(String headerName, String... headerValues) {
Assert.notNull(headerName, "HeaderName must not be null");
for (String headerValue : headerValues) {
this.headers.add(headerName, headerValue);
}
Expand All @@ -78,6 +79,7 @@ public ServerResponse.BodyBuilder header(String headerName, String... headerValu

@Override
public ServerResponse.BodyBuilder headers(Consumer<HttpHeaders> headersConsumer) {
Assert.notNull(headersConsumer, "HeaderConsumer must not be null");
headersConsumer.accept(this.headers);
return this;
}
Expand All @@ -91,18 +93,21 @@ public ServerResponse.BodyBuilder cookie(Cookie cookie) {

@Override
public ServerResponse.BodyBuilder cookies(Consumer<MultiValueMap<String, Cookie>> cookiesConsumer) {
Assert.notNull(cookiesConsumer, "CookiesConsumer must not be null");
cookiesConsumer.accept(this.cookies);
return this;
}

@Override
public ServerResponse.BodyBuilder allow(HttpMethod... allowedMethods) {
Assert.notNull(allowedMethods, "Http AllowedMethods must not be null");
this.headers.setAllow(new LinkedHashSet<>(Arrays.asList(allowedMethods)));
return this;
}

@Override
public ServerResponse.BodyBuilder allow(Set<HttpMethod> allowedMethods) {
Assert.notNull(allowedMethods, "Http AllowedMethods must not be null");
this.headers.setAllow(allowedMethods);
return this;
}
Expand All @@ -115,12 +120,14 @@ public ServerResponse.BodyBuilder contentLength(long contentLength) {

@Override
public ServerResponse.BodyBuilder contentType(MediaType contentType) {
Assert.notNull(contentType, "ContentType must not be null");
this.headers.setContentType(contentType);
return this;
}

@Override
public ServerResponse.BodyBuilder eTag(String etag) {
Assert.notNull(etag, "etag must not be null");
if (!etag.startsWith("\"") && !etag.startsWith("W/\"")) {
etag = "\"" + etag;
}
Expand Down