Skip to content

Untitled #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/com/ning/http/client/AsyncHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ public AsyncHttpClient(String providerClass, AsyncHttpClientConfig config) {
this.httpProvider = loadDefaultProvider(providerClass,config);
}

// LQ
public String toString() {
return httpProvider.toString();
}

public class BoundRequestBuilder extends RequestBuilderBase<BoundRequestBuilder> {
/**
* Calculator used for calculating request signature for the request being
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public T call() throws Exception {

int byteToRead = urlConnection.getContentLength();
InputStream stream = is;
if (byteToRead <= 0) {
/* if (byteToRead <= 0) */ { // content-length is not always defined properly by servers
int[] lengthWrapper = new int[1];
byte[] bytes = AsyncHttpProviderUtils.readFully(is, lengthWrapper);
stream = new ByteArrayInputStream(bytes, 0, lengthWrapper[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,12 @@ public class NettyAsyncHttpProvider extends SimpleChannelUpstreamHandler impleme
CleanupChannelGroup("asyncHttpClient") {
@Override
public boolean remove(Object o) {
maxConnections.decrementAndGet();
return super.remove(o);
boolean removed = super.remove(o); // LQ
if( removed ) {
// decrement maxConnections only if the channel has been removed.
maxConnections.decrementAndGet();
}
return removed;
}
};

Expand Down Expand Up @@ -202,6 +206,14 @@ public NettyAsyncHttpProvider(AsyncHttpClientConfig config) {
trackConnections = (config.getMaxTotalConnections() != -1);
}

// LQ
public String toString() {
return String.format("NettyAsyncHttpProvider:\n\t- maxConnections: %d\n\t- openChannels: %s\n\t- connectionPools: %s",
maxConnections.get(),
openChannels.toString(),
connectionsPool.toString());
}

void configureNetty() {
if (asyncHttpProviderConfig != null) {
for (Entry<String, Object> entry : asyncHttpProviderConfig.propertiesSet()) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/ning/http/util/AsyncHttpProviderUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ public static Cookie parseCookie(String value) {
}
}

// Normalization of maxAge (LQ)
if( maxAge < -1 ) {
maxAge = -1;
}

return new Cookie(domain, cookieName, cookieValue, path, maxAge, secure);
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/ning/http/util/UTF8UrlEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public static StringBuilder appendEncoded(StringBuilder sb, String input)

private final static void appendSingleByteEncoded(StringBuilder sb, int value)
{
// The space char must be converted into a + (some servers doesn't support the %20 notation for space)
if (value == 32) {
sb.append('+');
return;
}
sb.append('%');
sb.append(HEX[value >> 4]);
sb.append(HEX[value & 0xF]);
Expand Down