http-client-branch: review comment: small fixes to BufferingSubscriber, and add a User-Agent header
--- 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<ByteBuffer> buffers) {
- return buffers.stream().mapToInt(ByteBuffer::remaining).sum();
+ private static final long remaining(List<ByteBuffer> 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) {
--- 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<HttpClient.Version> version;
+ private static String userAgent() {
+ PrivilegedAction<String> 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