12
12
*/
13
13
package org .asynchttpclient .util ;
14
14
15
+ import static io .netty .handler .codec .http .HttpHeaders .Names .PROXY_AUTHORIZATION ;
15
16
import static java .nio .charset .StandardCharsets .ISO_8859_1 ;
16
17
import static org .asynchttpclient .util .HttpUtils .getNonEmptyPath ;
17
18
import static org .asynchttpclient .util .MiscUtils .isNonEmpty ;
28
29
import org .asynchttpclient .uri .Uri ;
29
30
30
31
public final class AuthenticatorUtils {
31
-
32
- public static final String NEGOTIATE = "Negotiate" ;
33
32
34
- private static final String PROXY_AUTHORIZATION_HEADER = "Proxy-Authorization " ;
33
+ public static final String NEGOTIATE = "Negotiate " ;
35
34
36
35
public static String getHeaderWithPrefix (List <String > authenticateHeaders , String prefix ) {
37
36
if (authenticateHeaders != null ) {
38
- for (String authenticateHeader : authenticateHeaders ) {
37
+ for (String authenticateHeader : authenticateHeaders ) {
39
38
if (authenticateHeader .regionMatches (true , 0 , prefix , 0 , prefix .length ()))
40
39
return authenticateHeader ;
41
40
}
42
41
}
43
42
44
43
return null ;
45
44
}
46
-
45
+
47
46
public static String computeBasicAuthentication (Realm realm ) {
48
47
return realm != null ? computeBasicAuthentication (realm .getPrincipal (), realm .getPassword (), realm .getCharset ()) : null ;
49
48
}
@@ -103,18 +102,14 @@ private static StringBuilder append(StringBuilder builder, String name, String v
103
102
return builder .append (", " );
104
103
}
105
104
106
- private static List <String > getProxyAuthorizationHeader (Request request ) {
107
- return request .getHeaders ().getAll (PROXY_AUTHORIZATION_HEADER );
108
- }
109
-
110
105
public static String perConnectionProxyAuthorizationHeader (Request request , Realm proxyRealm ) {
111
106
String proxyAuthorization = null ;
112
107
if (proxyRealm != null && proxyRealm .isUsePreemptiveAuth ()) {
113
108
switch (proxyRealm .getScheme ()) {
114
109
case NTLM :
115
110
case KERBEROS :
116
111
case SPNEGO :
117
- List <String > auth = getProxyAuthorizationHeader ( request );
112
+ List <String > auth = request . getHeaders (). getAll ( PROXY_AUTHORIZATION );
118
113
if (getHeaderWithPrefix (auth , "NTLM" ) == null ) {
119
114
String msg = NtlmEngine .INSTANCE .generateType1Msg ();
120
115
proxyAuthorization = "NTLM " + msg ;
@@ -127,12 +122,12 @@ public static String perConnectionProxyAuthorizationHeader(Request request, Real
127
122
128
123
return proxyAuthorization ;
129
124
}
130
-
125
+
131
126
public static String perRequestProxyAuthorizationHeader (Realm proxyRealm ) {
132
127
133
128
String proxyAuthorization = null ;
134
129
if (proxyRealm != null && proxyRealm .isUsePreemptiveAuth ()) {
135
-
130
+
136
131
switch (proxyRealm .getScheme ()) {
137
132
case BASIC :
138
133
proxyAuthorization = computeBasicAuthentication (proxyRealm );
0 commit comments