< prev index next >

src/java.httpclient/share/classes/java/net/http/Exchange.java

Print this page

        

*** 134,153 **** exchImpl = ExchangeImpl.get(this, connection); if (request.expectContinue()) { request.addSystemHeader("Expect", "100-Continue"); exchImpl.sendHeadersOnly(); HttpResponseImpl resp = exchImpl.getResponse(); ! logResponse(resp); if (resp.statusCode() != 100) { return resp; } exchImpl.sendBody(); return exchImpl.getResponse(); } else { exchImpl.sendRequest(); HttpResponseImpl resp = exchImpl.getResponse(); ! logResponse(resp); return checkForUpgrade(resp, exchImpl); } } // Completed HttpResponse will be null if response succeeded --- 134,153 ---- exchImpl = ExchangeImpl.get(this, connection); if (request.expectContinue()) { request.addSystemHeader("Expect", "100-Continue"); exchImpl.sendHeadersOnly(); HttpResponseImpl resp = exchImpl.getResponse(); ! Utils.logResponse(resp); if (resp.statusCode() != 100) { return resp; } exchImpl.sendBody(); return exchImpl.getResponse(); } else { exchImpl.sendRequest(); HttpResponseImpl resp = exchImpl.getResponse(); ! Utils.logResponse(resp); return checkForUpgrade(resp, exchImpl); } } // Completed HttpResponse will be null if response succeeded
*** 161,173 **** if (acc == null) { acc = request.getAccessControlContext(); } SecurityException e = securityCheck(acc); if (e != null) { ! CompletableFuture<HttpResponseImpl> cf = new CompletableFuture<>(); ! cf.completeExceptionally(e); ! return cf; } if (permissions.size() > 0) { return AccessController.doPrivileged( (PrivilegedAction<CompletableFuture<HttpResponseImpl>>)() -> responseAsyncImpl0(connection), --- 161,171 ---- if (acc == null) { acc = request.getAccessControlContext(); } SecurityException e = securityCheck(acc); if (e != null) { ! return CompletableFuture.failedFuture(e); } if (permissions.size() > 0) { return AccessController.doPrivileged( (PrivilegedAction<CompletableFuture<HttpResponseImpl>>)() -> responseAsyncImpl0(connection),
*** 180,192 **** CompletableFuture<HttpResponseImpl> responseAsyncImpl0(HttpConnection connection) { try { exchImpl = ExchangeImpl.get(this, connection); } catch (IOException | InterruptedException e) { ! CompletableFuture<HttpResponseImpl> cf = new CompletableFuture<>(); ! cf.completeExceptionally(e); ! return cf; } if (request.expectContinue()) { request.addSystemHeader("Expect", "100-Continue"); return exchImpl.sendHeadersAsync() .thenCompose(exchImpl::getResponseAsync) --- 178,188 ---- CompletableFuture<HttpResponseImpl> responseAsyncImpl0(HttpConnection connection) { try { exchImpl = ExchangeImpl.get(this, connection); } catch (IOException | InterruptedException e) { ! return CompletableFuture.failedFuture(e); } if (request.expectContinue()) { request.addSystemHeader("Expect", "100-Continue"); return exchImpl.sendHeadersAsync() .thenCompose(exchImpl::getResponseAsync)
*** 198,239 **** return cf; if (rcode == 100) { return exchImpl.sendBodyAsync() .thenCompose(exchImpl::getResponseAsync) .thenApply((r) -> { ! logResponse(r); return r; }); } else { Exchange.this.response = r1; ! logResponse(r1); return CompletableFuture.completedFuture(r1); } }); } else { return exchImpl ! .sendHeadersAsync() ! .thenCompose((Void v) -> { ! // send body and get response at same time ! return exchImpl.sendBodyAsync() ! .thenCompose(exchImpl::getResponseAsync); ! }) .thenCompose((HttpResponseImpl r1) -> { int rcode = r1.statusCode(); CompletableFuture<HttpResponseImpl> cf = checkForUpgradeAsync(r1, exchImpl); if (cf != null) { return cf; } else { Exchange.this.response = r1; ! logResponse(r1); return CompletableFuture.completedFuture(r1); } }) .thenApply((HttpResponseImpl response) -> { this.response = response; ! logResponse(response); return response; }); } } --- 194,231 ---- return cf; if (rcode == 100) { return exchImpl.sendBodyAsync() .thenCompose(exchImpl::getResponseAsync) .thenApply((r) -> { ! Utils.logResponse(r); return r; }); } else { Exchange.this.response = r1; ! Utils.logResponse(r1); return CompletableFuture.completedFuture(r1); } }); } else { return exchImpl ! .sendRequestAsync() ! .thenCompose(exchImpl::getResponseAsync) .thenCompose((HttpResponseImpl r1) -> { int rcode = r1.statusCode(); CompletableFuture<HttpResponseImpl> cf = checkForUpgradeAsync(r1, exchImpl); if (cf != null) { return cf; } else { Exchange.this.response = r1; ! Utils.logResponse(r1); return CompletableFuture.completedFuture(r1); } }) .thenApply((HttpResponseImpl response) -> { this.response = response; ! Utils.logResponse(response); return response; }); } }
*** 252,264 **** .thenCompose((Void v) -> Http2Connection.createAsync(e.connection(), client.client2(), this) .thenCompose((Http2Connection c) -> { Stream s = c.getStream(1); exchImpl = s; - c.putConnection(); return s.getResponseAsync(null); }) ); } return CompletableFuture.completedFuture(resp); --- 244,256 ---- .thenCompose((Void v) -> Http2Connection.createAsync(e.connection(), client.client2(), this) .thenCompose((Http2Connection c) -> { + c.putConnection(); Stream s = c.getStream(1); exchImpl = s; return s.getResponseAsync(null); }) ); } return CompletableFuture.completedFuture(resp);
*** 292,316 **** throw new UncheckedIOException(e); } } - private void logResponse(HttpResponseImpl r) { - if (!Log.requests()) - return; - StringBuilder sb = new StringBuilder(); - String method = r.request().method(); - URI uri = r.uri(); - String uristring = uri == null ? "" : uri.toString(); - sb.append('(') - .append(method) - .append(" ") - .append(uristring) - .append(") ") - .append(Integer.toString(r.statusCode())); - Log.logResponse(sb.toString()); - } <T> CompletableFuture<T> responseBodyAsync(HttpResponse.BodyProcessor<T> processor) { return exchImpl.responseBodyAsync(processor); } --- 284,293 ----
*** 350,362 **** if (sm == null) { return null; } String method = request.method(); ! HttpHeadersImpl userHeaders = request.getUserHeaders(); URI u = getURIForSecurityCheck(); ! URLPermission p = Utils.getPermission(u, method, userHeaders.directMap()); try { assert acc != null; sm.checkPermission(p, acc); permissions.add(getSocketPermissionFor(u)); --- 327,339 ---- if (sm == null) { return null; } String method = request.method(); ! HttpHeaders userHeaders = request.getUserHeaders(); URI u = getURIForSecurityCheck(); ! URLPermission p = Utils.getPermission(u, method, userHeaders.map()); try { assert acc != null; sm.checkPermission(p, acc); permissions.add(getSocketPermissionFor(u));
< prev index next >