Skip to content

Commit e485abb

Browse files
committed
Fix checkstyle violation (plus related polishing)
Issue: SPR-16913
1 parent d08b72a commit e485abb

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

spring-web/src/main/java/org/springframework/http/HttpHeaders.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ public ZonedDateTime getFirstZonedDateTime(String headerName) {
12861286
* {@link IllegalArgumentException} ({@code true}) or rather return {@code null}
12871287
* in that case ({@code false})
12881288
* @return the parsed date header, or {@code null} if none (or invalid)
1289-
*/
1289+
*/
12901290
@Nullable
12911291
private ZonedDateTime getFirstZonedDateTime(String headerName, boolean rejectInvalid) {
12921292
String headerValue = getFirst(headerName);
@@ -1570,57 +1570,52 @@ public static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers) {
15701570
}
15711571

15721572
/**
1573-
* Returns a {@code HttpHeaders} consumer that adds Basic Authentication.
1573+
* Return a {@code HttpHeaders} consumer that adds Basic Authentication.
15741574
* More specifically: a consumer that adds an {@linkplain #AUTHORIZATION
1575-
* Authorization} header based on the given username and password. Meant
1576-
* to be used in combination with
1575+
* Authorization} header based on the given username and password.
1576+
* Meant to be used in combination with
15771577
* {@link org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec#headers(java.util.function.Consumer)}.
15781578
* <p>Note that Basic Authentication only supports characters in the
15791579
* {@linkplain StandardCharsets#ISO_8859_1 ISO-8859-1} character set.
1580-
*
15811580
* @param username the username
15821581
* @param password the password
15831582
* @return a consumer that adds a Basic Authentication header
1583+
* @since 5.1
15841584
*/
1585-
public static Consumer<HttpHeaders> basicAuthenticationConsumer(String username,String password) {
1585+
public static Consumer<HttpHeaders> basicAuthenticationConsumer(String username, String password) {
15861586
return basicAuthenticationConsumer(() -> username, () -> password);
15871587

15881588
}
15891589

15901590
/**
1591-
* Returns a {@code HttpHeaders} consumer that adds Basic Authentication.
1591+
* Return a {@code HttpHeaders} consumer that adds Basic Authentication.
15921592
* More specifically: a consumer that adds an {@linkplain #AUTHORIZATION
15931593
* Authorization} header based on the given username and password
15941594
* suppliers. Meant to be used in combination with
15951595
* {@link org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec#headers(java.util.function.Consumer)}.
15961596
* <p>Note that Basic Authentication only supports characters in the
15971597
* {@linkplain StandardCharsets#ISO_8859_1 ISO-8859-1} character set.
1598-
*
15991598
* @param usernameSupplier supplier for the username
16001599
* @param passwordSupplier supplier for the password
16011600
* @return a consumer that adds a Basic Authentication header
1601+
* @since 5.1
16021602
*/
1603-
public static Consumer<HttpHeaders> basicAuthenticationConsumer(Supplier<String> usernameSupplier,
1604-
Supplier<String> passwordSupplier) {
1603+
public static Consumer<HttpHeaders> basicAuthenticationConsumer(
1604+
Supplier<String> usernameSupplier, Supplier<String> passwordSupplier) {
16051605

16061606
Assert.notNull(usernameSupplier, "Username Supplier must not be null");
16071607
Assert.notNull(passwordSupplier, "Password Supplier must not be null");
1608-
16091608
return new BasicAuthenticationConsumer(usernameSupplier, passwordSupplier);
16101609
}
16111610

16121611

1613-
/**
1614-
* @see #basicAuthenticationConsumer
1615-
*/
16161612
private static class BasicAuthenticationConsumer implements Consumer<HttpHeaders> {
16171613

16181614
private final Supplier<String> usernameSupplier;
16191615

16201616
private final Supplier<String> passwordSupplier;
16211617

1622-
public BasicAuthenticationConsumer(Supplier<String> usernameSupplier,
1623-
Supplier<String> passwordSupplier) {
1618+
public BasicAuthenticationConsumer(Supplier<String> usernameSupplier, Supplier<String> passwordSupplier) {
16241619
this.usernameSupplier = usernameSupplier;
16251620
this.passwordSupplier = passwordSupplier;
16261621
}
@@ -1629,17 +1624,14 @@ public BasicAuthenticationConsumer(Supplier<String> usernameSupplier,
16291624
public void accept(HttpHeaders httpHeaders) {
16301625
String username = this.usernameSupplier.get();
16311626
String password = this.passwordSupplier.get();
1632-
16331627
Assert.state(username != null, "Supplied username is null");
16341628
Assert.state(password != null, "Supplied password is null");
1635-
16361629
checkIllegalCharacters(username, password);
16371630

16381631
String credentialsString = username + ":" + password;
16391632
byte[] credentialBytes = credentialsString.getBytes(StandardCharsets.ISO_8859_1);
16401633
byte[] encodedBytes = Base64.getEncoder().encode(credentialBytes);
16411634
String encodedCredentials = new String(encodedBytes, StandardCharsets.ISO_8859_1);
1642-
16431635
httpHeaders.set(HttpHeaders.AUTHORIZATION, "Basic " + encodedCredentials);
16441636
}
16451637

@@ -1651,6 +1643,6 @@ private static void checkIllegalCharacters(String username, String password) {
16511643
"Username or password contains characters that cannot be encoded to ISO-8859-1");
16521644
}
16531645
}
1654-
16551646
}
1647+
16561648
}

0 commit comments

Comments
 (0)