Merge http-client-branch
authordfuchs
Wed, 06 Dec 2017 12:18:08 +0000
branchhttp-client-branch
changeset 55963 ae2750657f98
parent 55959 7fd1a84f4fae (diff)
parent 55962 35376c843df1 (current diff)
child 55964 b2e6f2945ac3
Merge
test/jdk/java/net/httpclient/SplitResponse.java
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/BufferingSubscriber.java	Wed Dec 06 10:44:31 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/BufferingSubscriber.java	Wed Dec 06 12:18:08 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:44:31 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/HttpRequestImpl.java	Wed Dec 06 12:18:08 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
--- a/test/jdk/java/net/httpclient/SplitResponse.java	Wed Dec 06 10:44:31 2017 +0000
+++ b/test/jdk/java/net/httpclient/SplitResponse.java	Wed Dec 06 12:18:08 2017 +0000
@@ -137,7 +137,7 @@
         // MockServer will reject rogue requests whose URI does not
         // contain "/foo/".
         //
-        //        Thread go = new Thread() {
+        //        Thread rogue = new Thread() {
         //            public void run() {
         //                try {
         //                    HttpClient client = newHttpClient();
@@ -156,8 +156,8 @@
         //                }
         //            }
         //        };
-        //        go.setDaemon(true);
-        //        go.start();
+        //        rogue.setDaemon(true);
+        //        rogue.start();
 
 
         HttpClient client = newHttpClient();