Skip to content
Permalink
Browse files
Minor Improvement:
* Avoid duplicate code
* Simplify if else
* Inline variables
  • Loading branch information
arturobernalg authored and ok2c committed Feb 5, 2021
1 parent c2e6f92 commit 0940d35602f505a9c0026ea7ef353971af5e4ab8
Show file tree
Hide file tree
Showing 15 changed files with 19 additions and 53 deletions.
@@ -287,10 +287,7 @@ public boolean allConditionalsMatch(final HttpRequest request, final HttpCacheEn
return false;
}

if (hasLastModifiedValidator && !lastModifiedValidatorMatches) {
return false;
}
return true;
return !hasLastModifiedValidator || lastModifiedValidatorMatches;
}

private boolean hasUnsupportedConditionalHeaders(final HttpRequest request) {
@@ -325,11 +325,7 @@ boolean clientRequestsOurOptions(final HttpRequest request) {
}

final Header h = request.getFirstHeader(HeaderConstants.MAX_FORWARDS);
if (!"0".equals(h != null ? h.getValue() : null)) {
return false;
}

return true;
return "0".equals(h != null ? h.getValue() : null);
}

boolean revalidationResponseIsTooOld(final HttpResponse backendResponse, final HttpCacheEntry cacheEntry) {
@@ -159,11 +159,7 @@ protected boolean requestMinorVersionIsTooHighMajorVersionsMatch(final HttpReque
return false;
}

if (requestProtocol.getMinor() > HttpVersion.HTTP_1_1.getMinor()) {
return true;
}

return false;
return requestProtocol.getMinor() > HttpVersion.HTTP_1_1.getMinor();
}

protected boolean requestVersionIsTooLow(final HttpRequest request) {
@@ -192,10 +192,7 @@ private boolean unknownStatusCode(final int status) {
if (status >= 400 && status <= 417) {
return false;
}
if (status >= 500 && status <= 505) {
return false;
}
return true;
return status < 500 || status > 505;
}

protected boolean isExplicitlyNonCacheable(final HttpResponse response) {
@@ -119,17 +119,15 @@ protected void consumeLinearWhitespace() {
* CHAR = <any US-ASCII character (octets 0 - 127)>
*/
private boolean isChar(final char c) {
final int i = c;
return (i >= 0 && i <= 127);
return ((int) c >= 0 && (int) c <= 127);
}

/*
* CTL = <any US-ASCII control character
(octets 0 - 31) and DEL (127)>
*/
private boolean isControl(final char c) {
final int i = c;
return (i == 127 || (i >=0 && i <= 31));
return ((int) c == 127 || ((int) c >=0 && (int) c <= 31));
}

/*
@@ -87,8 +87,7 @@ public void handle(final ClassicHttpRequest request,
contentType = contentTypeStr == null ? null : ContentType.parse(contentTypeStr);
}

final ByteArrayEntity bae = new ByteArrayEntity(data, contentType);
entity = bae;
entity = new ByteArrayEntity(data, contentType);

response.setCode(HttpStatus.SC_OK);
response.setEntity(entity);
@@ -71,9 +71,7 @@ public boolean equals(final Object o) {
}
if (o instanceof BasicUserPrincipal) {
final BasicUserPrincipal that = (BasicUserPrincipal) o;
if (LangUtils.equals(this.username, that.username)) {
return true;
}
return LangUtils.equals(this.username, that.username);
}
return false;
}
@@ -159,11 +159,9 @@ public boolean equals(final Object o) {
}
if (o instanceof NTCredentials) {
final NTCredentials that = (NTCredentials) o;
if (LangUtils.equals(this.principal, that.principal)
return LangUtils.equals(this.principal, that.principal)
&& LangUtils.equals(this.workstation, that.workstation)
&& LangUtils.equals(this.netbiosDomain, that.netbiosDomain)) {
return true;
}
&& LangUtils.equals(this.netbiosDomain, that.netbiosDomain);
}
return false;
}
@@ -99,10 +99,8 @@ public boolean equals(final Object o) {
}
if (o instanceof NTUserPrincipal) {
final NTUserPrincipal that = (NTUserPrincipal) o;
if (LangUtils.equals(this.username, that.username)
&& LangUtils.equals(this.domain, that.domain)) {
return true;
}
return LangUtils.equals(this.username, that.username)
&& LangUtils.equals(this.domain, that.domain);
}
return false;
}
@@ -87,9 +87,7 @@ public boolean equals(final Object o) {
}
if (o instanceof UsernamePasswordCredentials) {
final UsernamePasswordCredentials that = (UsernamePasswordCredentials) o;
if (LangUtils.equals(this.principal, that.principal)) {
return true;
}
return LangUtils.equals(this.principal, that.principal);
}
return false;
}
@@ -333,12 +333,11 @@ private String createDigestResponse(final HttpRequest request) throws Authentica
final String checksum = formatHex(digester.digest(this.buffer.toByteArray()));
buffer.reset();
buffer.append(checksum).append(":").append(nonce).append(":").append(cnonce);
a1 = buffer.toByteArray();
} else {
// unq(username-value) ":" unq(realm-value) ":" passwd
buffer.append(username).append(":").append(realm).append(":").append(password);
a1 = buffer.toByteArray();
}
a1 = buffer.toByteArray();

final String hasha1 = formatHex(digester.digest(a1));
buffer.reset();
@@ -383,13 +382,12 @@ private String createDigestResponse(final HttpRequest request) throws Authentica
final byte[] digestInput;
if (qop == QOP_MISSING) {
buffer.append(hasha1).append(":").append(nonce).append(":").append(hasha2);
digestInput = buffer.toByteArray();
} else {
buffer.append(hasha1).append(":").append(nonce).append(":").append(nc).append(":")
.append(cnonce).append(":").append(qop == QOP_AUTH_INT ? "auth-int" : "auth")
.append(":").append(hasha2);
digestInput = buffer.toByteArray();
}
digestInput = buffer.toByteArray();
buffer.reset();

final String digest = formatHex(digester.digest(digestInput));
@@ -103,9 +103,7 @@ static boolean domainMatch(final String domain, final String host) {
if (prefix == 0) {
return true;
}
if (prefix > 1 && host.charAt(prefix - 1) == '.') {
return true;
}
return prefix > 1 && host.charAt(prefix - 1) == '.';
}
return false;
}
@@ -75,9 +75,7 @@ static boolean pathMatch(final String uriPath, final String cookiePath) {
if (uriPath.length() == normalizedCookiePath.length()) {
return true;
}
if (uriPath.charAt(normalizedCookiePath.length()) == '/') {
return true;
}
return uriPath.charAt(normalizedCookiePath.length()) == '/';
}
return false;
}
@@ -138,8 +138,7 @@ public String getDomainRoot(final String domain, final DomainType expectedType)
if (domain.startsWith(".")) {
return null;
}
final String normalized = DnsUtils.normalize(domain);
String segment = normalized;
String segment = DnsUtils.normalize(domain);
String result = null;
while (segment != null) {
// An exception rule takes priority over any other matching rule.
@@ -220,9 +220,7 @@ private static boolean matchIdentity(final String host, final String identity,
if (strict) {
final String remainder = host.substring(
prefix.length(), host.length() - suffix.length());
if (remainder.contains(".")) {
return false;
}
return !remainder.contains(".");
}
return true;
}

0 comments on commit 0940d35

Please sign in to comment.