Skip to content

Commit 03ecb4d

Browse files
committed
No need for custom constant, use Netty's
1 parent 2ffab47 commit 03ecb4d

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

client/src/main/java/org/asynchttpclient/util/AuthenticatorUtils.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
package org.asynchttpclient.util;
1414

15+
import static io.netty.handler.codec.http.HttpHeaders.Names.PROXY_AUTHORIZATION;
1516
import static java.nio.charset.StandardCharsets.ISO_8859_1;
1617
import static org.asynchttpclient.util.HttpUtils.getNonEmptyPath;
1718
import static org.asynchttpclient.util.MiscUtils.isNonEmpty;
@@ -28,22 +29,20 @@
2829
import org.asynchttpclient.uri.Uri;
2930

3031
public final class AuthenticatorUtils {
31-
32-
public static final String NEGOTIATE = "Negotiate";
3332

34-
private static final String PROXY_AUTHORIZATION_HEADER = "Proxy-Authorization";
33+
public static final String NEGOTIATE = "Negotiate";
3534

3635
public static String getHeaderWithPrefix(List<String> authenticateHeaders, String prefix) {
3736
if (authenticateHeaders != null) {
38-
for (String authenticateHeader: authenticateHeaders) {
37+
for (String authenticateHeader : authenticateHeaders) {
3938
if (authenticateHeader.regionMatches(true, 0, prefix, 0, prefix.length()))
4039
return authenticateHeader;
4140
}
4241
}
4342

4443
return null;
4544
}
46-
45+
4746
public static String computeBasicAuthentication(Realm realm) {
4847
return realm != null ? computeBasicAuthentication(realm.getPrincipal(), realm.getPassword(), realm.getCharset()) : null;
4948
}
@@ -103,18 +102,14 @@ private static StringBuilder append(StringBuilder builder, String name, String v
103102
return builder.append(", ");
104103
}
105104

106-
private static List<String> getProxyAuthorizationHeader(Request request) {
107-
return request.getHeaders().getAll(PROXY_AUTHORIZATION_HEADER);
108-
}
109-
110105
public static String perConnectionProxyAuthorizationHeader(Request request, Realm proxyRealm) {
111106
String proxyAuthorization = null;
112107
if (proxyRealm != null && proxyRealm.isUsePreemptiveAuth()) {
113108
switch (proxyRealm.getScheme()) {
114109
case NTLM:
115110
case KERBEROS:
116111
case SPNEGO:
117-
List<String> auth = getProxyAuthorizationHeader(request);
112+
List<String> auth = request.getHeaders().getAll(PROXY_AUTHORIZATION);
118113
if (getHeaderWithPrefix(auth, "NTLM") == null) {
119114
String msg = NtlmEngine.INSTANCE.generateType1Msg();
120115
proxyAuthorization = "NTLM " + msg;
@@ -127,12 +122,12 @@ public static String perConnectionProxyAuthorizationHeader(Request request, Real
127122

128123
return proxyAuthorization;
129124
}
130-
125+
131126
public static String perRequestProxyAuthorizationHeader(Realm proxyRealm) {
132127

133128
String proxyAuthorization = null;
134129
if (proxyRealm != null && proxyRealm.isUsePreemptiveAuth()) {
135-
130+
136131
switch (proxyRealm.getScheme()) {
137132
case BASIC:
138133
proxyAuthorization = computeBasicAuthentication(proxyRealm);

0 commit comments

Comments
 (0)