# HG changeset patch # User chegar # Date 1512561938 0 # Node ID 7fd1a84f4faef64042a39db1bdf68b33b5eaa9ef # Parent 24e637188a68a9da88b1e62fd067a350ccbd4fa5 http-client-branch: review comment: small fixes to BufferingSubscriber, and add a User-Agent header diff -r 24e637188a68 -r 7fd1a84f4fae src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/BufferingSubscriber.java --- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/BufferingSubscriber.java Wed Dec 06 10:33:27 2017 +0000 +++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/BufferingSubscriber.java Wed Dec 06 12:05:38 2017 +0000 @@ -89,8 +89,8 @@ } /** Returns the number of bytes remaining in the given buffers. */ - private static final int remaining(List buffers) { - return buffers.stream().mapToInt(ByteBuffer::remaining).sum(); + private static final long remaining(List buffers) { + return buffers.stream().mapToLong(ByteBuffer::remaining).sum(); } /** @@ -190,8 +190,8 @@ try { Throwable t = throwable; if (t != null) { + pushDemandedScheduler.stop(); // stop the demand scheduler downstreamSubscriber.onError(t); - pushDemandedScheduler.stop(); // stop the demand scheduler return; } @@ -219,8 +219,9 @@ complete = state == COMPLETE && internalBuffers.isEmpty(); } if (complete) { + assert internalBuffers.isEmpty(); + pushDemandedScheduler.stop(); // stop the demand scheduler downstreamSubscriber.onComplete(); - pushDemandedScheduler.stop(); // stop the demand scheduler return; } } catch (Throwable t) { diff -r 24e637188a68 -r 7fd1a84f4fae src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpRequestImpl.java --- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpRequestImpl.java Wed Dec 06 10:33:27 2017 +0000 +++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpRequestImpl.java Wed Dec 06 12:05:38 2017 +0000 @@ -59,6 +59,15 @@ private final Duration timeout; // may be null private final Optional version; + private static String userAgent() { + PrivilegedAction pa = () -> System.getProperty("java.version"); + String version = AccessController.doPrivileged(pa); + return "Java-http-client/" + version; + } + + /** The value of the User-Agent header for all requests sent by the client. */ + public static final String USER_AGENT = userAgent(); + /** * Creates an HttpRequestImpl from the given builder. */ @@ -90,6 +99,7 @@ } else { this.systemHeaders = new HttpHeadersImpl(); } + this.systemHeaders.setHeader("User-Agent", USER_AGENT); this.uri = request.uri(); if (isWebSocket) { // WebSocket determines and sets the proxy itself