Skip to content

Commit c00b2b0

Browse files
committed
Changes for AsyncHttpClient#234 and more.
- changed occurrences of .equals("") to use .length() instead. - Fixed random test failures where test cases expected post data to come in one chunk - this may not always be the case.
1 parent 3caad23 commit c00b2b0

File tree

9 files changed

+33
-23
lines changed

9 files changed

+33
-23
lines changed

api/src/main/java/com/ning/http/client/Realm.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010 Ning, Inc.
2+
* Copyright 2010-2013 Ning, Inc.
33
*
44
* Ning licenses this file to you under the Apache License, version 2.0
55
* (the "License"); you may not use this file except in compliance with the
@@ -538,7 +538,7 @@ private void newResponse() throws UnsupportedEncodingException {
538538
.append(uri).toString().getBytes("ISO-8859-1"));
539539
byte[] ha2 = md.digest();
540540

541-
if(qop==null || qop.equals("")) {
541+
if(qop==null || qop.length() == 0) {
542542
md.update(new StringBuilder(toBase16(ha1))
543543
.append(':')
544544
.append(nonce)
@@ -599,7 +599,7 @@ private static String toBase16(byte[] bytes) {
599599
public Realm build() {
600600

601601
// Avoid generating
602-
if (nonce != null && !nonce.equals("")) {
602+
if (nonce != null && nonce.length() > 0) {
603603
newCnonce();
604604
try {
605605
newResponse();

api/src/main/java/com/ning/http/client/RequestBuilderBase.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010 Ning, Inc.
2+
* Copyright 2010-2013 Ning, Inc.
33
*
44
* Ning licenses this file to you under the Apache License, version 2.0
55
* (the "License"); you may not use this file except in compliance with the
@@ -163,7 +163,7 @@ private String toUrl(boolean encode) {
163163
} else {
164164
builder.append(name);
165165
}
166-
if (value != null && !value.equals("")) {
166+
if (value != null) {
167167
builder.append('=');
168168
if (encode) {
169169
UTF8UrlEncoder.appendEncoded(builder, value);
@@ -384,11 +384,11 @@ private String buildUrl(String url) {
384384
}
385385
}
386386

387-
if (uri.getRawQuery() != null && !uri.getRawQuery().equals("")) {
387+
if (uri.getRawQuery() != null && uri.getRawQuery().length() > 0) {
388388
String[] queries = uri.getRawQuery().split("&");
389389
int pos;
390390
for (String query : queries) {
391-
pos = query.indexOf("=");
391+
pos = query.indexOf('=');
392392
if (pos <= 0) {
393393
addQueryParameter(query, null);
394394
} else {

api/src/main/java/com/ning/http/client/ntlm/NTLMEngine.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved.
2+
* Copyright (c) 2010-2013 Sonatype, Inc. All rights reserved.
33
*
44
* This program is licensed to you under the Apache License Version 2.0,
55
* and you may not use this file except in compliance with the Apache License Version 2.0.
@@ -123,7 +123,7 @@ final String getResponseFor(String message, String username, String password,
123123
String host, String domain) throws NTLMEngineException {
124124

125125
final String response;
126-
if (message == null || message.trim().equals("")) {
126+
if (message == null || message.trim().length() == 0) {
127127
response = getType1Message(host, domain);
128128
} else {
129129
Type2Message t2m = new Type2Message(message);

api/src/main/java/com/ning/http/client/providers/jdk/JDKAsyncHttpProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved.
2+
* Copyright (c) 2010-2013 Sonatype, Inc. All rights reserved.
33
*
44
* This program is licensed to you under the Apache License Version 2.0,
55
* and you may not use this file except in compliance with the Apache License Version 2.0.
@@ -516,7 +516,7 @@ private void configure(URI uri, HttpURLConnection urlConnection, Request request
516516
AuthenticatorUtils.computeBasicAuthentication(realm));
517517
break;
518518
case DIGEST:
519-
if (realm.getNonce() != null && !realm.getNonce().equals("")) {
519+
if (realm.getNonce() != null && realm.getNonce().length() > 0) {
520520
try {
521521
urlConnection.setRequestProperty("Authorization",
522522
AuthenticatorUtils.computeDigestAuthentication(realm));

api/src/main/java/com/ning/http/util/AuthenticatorUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved.
2+
* Copyright (c) 2010-2013 Sonatype, Inc. All rights reserved.
33
*
44
* This program is licensed to you under the Apache License Version 2.0,
55
* and you may not use this file except in compliance with the Apache License Version 2.0.
@@ -40,7 +40,7 @@ public static String computeDigestAuthentication(Realm realm) throws NoSuchAlgor
4040
builder.append("algorithm").append('=').append(realm.getAlgorithm()).append(", ");
4141

4242
construct(builder, "response", realm.getResponse());
43-
if (realm.getOpaque() != null && realm.getOpaque() != null && realm.getOpaque().equals("") == false)
43+
if (realm.getOpaque() != null && realm.getOpaque().length() > 0)
4444
construct(builder, "opaque", realm.getOpaque());
4545
builder.append("qop").append('=').append(realm.getQop()).append(", ");
4646
builder.append("nc").append('=').append(realm.getNc()).append(", ");

api/src/test/java/com/ning/http/client/async/BasicHttpsTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,15 @@ public void handle(String pathInContext,
122122
size = httpRequest.getContentLength();
123123
}
124124
byte[] bytes = new byte[size];
125+
int pos = 0;
125126
if (bytes.length > 0) {
126-
//noinspection ResultOfMethodCallIgnored
127-
int read = httpRequest.getInputStream().read(bytes);
128-
httpResponse.getOutputStream().write(bytes, 0, read);
127+
int read = 0;
128+
while (read != -1) {
129+
read = httpRequest.getInputStream().read(bytes, pos, bytes.length - pos);
130+
pos += read;
131+
}
132+
133+
httpResponse.getOutputStream().write(bytes);
129134
}
130135

131136
httpResponse.setStatus(200);

api/src/test/java/com/ning/http/client/async/HostnameVerifierTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,15 @@ public void handle(String pathInContext,
113113
size = httpRequest.getContentLength();
114114
}
115115
byte[] bytes = new byte[size];
116+
int pos = 0;
116117
if (bytes.length > 0) {
117-
//noinspection ResultOfMethodCallIgnored
118-
int read = httpRequest.getInputStream().read(bytes);
119-
httpResponse.getOutputStream().write(bytes, 0, read);
118+
int read = 0;
119+
while (read != -1) {
120+
read = httpRequest.getInputStream().read(bytes, pos, bytes.length - pos);
121+
pos += read;
122+
}
123+
124+
httpResponse.getOutputStream().write(bytes);
120125
}
121126

122127
httpResponse.setStatus(200);

api/src/test/java/com/ning/http/client/async/PostWithQSTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void postWithNulParamQS() throws IOException, ExecutionException, Timeout
8989

9090
/* @Override */
9191
public STATE onStatusReceived(final HttpResponseStatus status) throws Exception {
92-
if (!status.getUrl().toURL().toString().equals("http://127.0.0.1/" + port1 + "/?a")) {
92+
if (!status.getUrl().toURL().toString().equals("http://127.0.0.1/" + port1 + "/?a=")) {
9393
throw new IOException(status.getUrl().toURL().toString());
9494
}
9595
return super.onStatusReceived(status);
@@ -109,7 +109,7 @@ public void postWithNulParamsQS() throws IOException, ExecutionException, Timeou
109109

110110
/* @Override */
111111
public STATE onStatusReceived(final HttpResponseStatus status) throws Exception {
112-
if (!status.getUrl().toURL().toString().equals("http://127.0.0.1/" + port1 + "/?a=b&c&d=e")) {
112+
if (!status.getUrl().toURL().toString().equals("http://127.0.0.1/" + port1 + "/?a=b&c=&d=e")) {
113113
throw new IOException("failed to parse the query properly");
114114
}
115115
return super.onStatusReceived(status);

providers/netty/src/main/java/com/ning/http/client/providers/netty/NettyAsyncHttpProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010 Ning, Inc.
2+
* Copyright 2010-2013 Ning, Inc.
33
*
44
* Ning licenses this file to you under the Apache License, version 2.0
55
* (the "License"); you may not use this file except in compliance with the
@@ -668,7 +668,7 @@ private static HttpRequest construct(AsyncHttpClientConfig config,
668668
AuthenticatorUtils.computeBasicAuthentication(realm));
669669
break;
670670
case DIGEST:
671-
if (realm.getNonce() != null && !realm.getNonce().equals("")) {
671+
if (realm.getNonce() != null && realm.getNonce().length() > 0) {
672672
try {
673673
nettyRequest.setHeader(HttpHeaders.Names.AUTHORIZATION,
674674
AuthenticatorUtils.computeDigestAuthentication(realm));

0 commit comments

Comments
 (0)