Skip to content

Commit 7f95417

Browse files
author
Stephane Landelle
committed
Make Realm and ProxyServer encoding Charsets instead of Strings, close AsyncHttpClient#708
1 parent 6e04180 commit 7f95417

File tree

4 files changed

+17
-28
lines changed

4 files changed

+17
-28
lines changed

api/src/main/java/org/asynchttpclient/ProxyServer.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public String toString() {
5454
private final String password;
5555
private final int port;
5656
private final String url;
57-
private String encoding = UTF_8.name();
5857
private Charset charset = UTF_8;
5958
private String ntlmDomain = System.getProperty("http.auth.ntlm.domain", "");
6059

@@ -103,16 +102,11 @@ public String getPassword() {
103102
return password;
104103
}
105104

106-
public ProxyServer setEncoding(String encoding) {
107-
this.encoding = encoding;
108-
this.charset = Charset.forName(encoding);
105+
public ProxyServer setCharset(Charset charset) {
106+
this.charset = charset;
109107
return this;
110108
}
111109

112-
public String getEncoding() {
113-
return encoding;
114-
}
115-
116110
public Charset getCharset() {
117111
return charset;
118112
}

api/src/main/java/org/asynchttpclient/Realm.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ public class Realm {
4646
private final Uri uri;
4747
private final String methodName;
4848
private final boolean usePreemptiveAuth;
49-
private final String enc;
49+
private final Charset charset;
5050
private final String host;
5151
private final boolean messageType2Received;
5252
private final String ntlmDomain;
53-
private final Charset charset;
5453
private final boolean useAbsoluteURI;
5554
private final boolean omitQuery;
5655
private final boolean targetProxy;
@@ -60,7 +59,7 @@ public enum AuthScheme {
6059
}
6160

6261
private Realm(AuthScheme scheme, String principal, String password, String realmName, String nonce, String algorithm, String response,
63-
String qop, String nc, String cnonce, Uri uri, String method, boolean usePreemptiveAuth, String ntlmDomain, String enc,
62+
String qop, String nc, String cnonce, Uri uri, String method, boolean usePreemptiveAuth, String ntlmDomain, Charset charset,
6463
String host, boolean messageType2Received, String opaque, boolean useAbsoluteURI, boolean omitQuery, boolean targetProxy) {
6564

6665
this.principal = principal;
@@ -78,10 +77,9 @@ private Realm(AuthScheme scheme, String principal, String password, String realm
7877
this.methodName = method;
7978
this.usePreemptiveAuth = usePreemptiveAuth;
8079
this.ntlmDomain = ntlmDomain;
81-
this.enc = enc;
8280
this.host = host;
8381
this.messageType2Received = messageType2Received;
84-
this.charset = enc != null ? Charset.forName(enc) : null;
82+
this.charset = charset;
8583
this.useAbsoluteURI = useAbsoluteURI;
8684
this.omitQuery = omitQuery;
8785
this.targetProxy = targetProxy;
@@ -140,10 +138,6 @@ public Uri getUri() {
140138
return uri;
141139
}
142140

143-
public String getEncoding() {
144-
return enc;
145-
}
146-
147141
public Charset getCharset() {
148142
return charset;
149143
}
@@ -279,7 +273,7 @@ public static class RealmBuilder {
279273
private String methodName = "GET";
280274
private boolean usePreemptive;
281275
private String ntlmDomain = System.getProperty("http.auth.ntlm.domain", "");
282-
private String enc = UTF_8.name();
276+
private Charset charset = UTF_8;
283277
private String host = "localhost";
284278
private boolean messageType2Received;
285279
private boolean useAbsoluteURI = true;
@@ -492,7 +486,7 @@ public RealmBuilder clone(Realm clone) {
492486
setNonce(clone.getNonce());
493487
setPassword(clone.getPassword());
494488
setPrincipal(clone.getPrincipal());
495-
setEncoding(clone.getEncoding());
489+
setCharset(clone.getCharset());
496490
setOpaque(clone.getOpaque());
497491
setQop(clone.getQop());
498492
setScheme(clone.getScheme());
@@ -537,12 +531,12 @@ private String match(String headerLine, String token) {
537531
return value.charAt(0) == '"' ? value.substring(1) : value;
538532
}
539533

540-
public String getEncoding() {
541-
return enc;
534+
public Charset getCharset() {
535+
return charset;
542536
}
543537

544-
public RealmBuilder setEncoding(String enc) {
545-
this.enc = enc;
538+
public RealmBuilder setCharset(Charset charset) {
539+
this.charset = charset;
546540
return this;
547541
}
548542

@@ -629,7 +623,7 @@ public Realm build() {
629623
}
630624

631625
return new Realm(scheme, principal, password, realmName, nonce, algorithm, response, qop, nc, cnonce, uri, methodName,
632-
usePreemptive, ntlmDomain, enc, host, messageType2Received, opaque, useAbsoluteURI, omitQuery, targetProxy);
626+
usePreemptive, ntlmDomain, charset, host, messageType2Received, opaque, useAbsoluteURI, omitQuery, targetProxy);
633627
}
634628
}
635629
}

api/src/main/java/org/asynchttpclient/SimpleAsyncHttpClient.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import java.io.Closeable;
1818
import java.io.IOException;
19+
import java.nio.charset.Charset;
1920
import java.util.Collection;
2021
import java.util.List;
2122
import java.util.Map;
@@ -583,8 +584,8 @@ public Builder setRealmUsePreemptiveAuth(boolean usePreemptiveAuth) {
583584
return this;
584585
}
585586

586-
public Builder setRealmEnconding(String enc) {
587-
realm().setEncoding(enc);
587+
public Builder setRealmCharset(Charset charset) {
588+
realm().setCharset(charset);
588589
return this;
589590
}
590591

api/src/test/java/org/asynchttpclient/RealmTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ public class RealmTest {
2828
public void testClone() {
2929
RealmBuilder builder = new RealmBuilder();
3030
builder.setPrincipal("user").setPassword("pass");
31-
builder.setEncoding(UTF_8.name()).setUsePreemptiveAuth(true);
31+
builder.setCharset(UTF_16).setUsePreemptiveAuth(true);
3232
builder.setRealmName("realm").setAlgorithm("algo");
3333
builder.setScheme(AuthScheme.BASIC);
3434
Realm orig = builder.build();
3535

3636
Realm clone = new RealmBuilder().clone(orig).build();
3737
assertEquals(clone.getPrincipal(), orig.getPrincipal());
3838
assertEquals(clone.getPassword(), orig.getPassword());
39-
assertEquals(clone.getEncoding(), orig.getEncoding());
39+
assertEquals(clone.getCharset(), orig.getCharset());
4040
assertEquals(clone.getUsePreemptiveAuth(), orig.getUsePreemptiveAuth());
4141
assertEquals(clone.getRealmName(), orig.getRealmName());
4242
assertEquals(clone.getAlgorithm(), orig.getAlgorithm());

0 commit comments

Comments
 (0)