src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Stream.java
branchhttp-client-branch
changeset 56054 352e845ae744
parent 56041 b4b5e09ef3cc
child 56071 3353cb42b1b4
equal deleted inserted replaced
56053:8588095e95b0 56054:352e845ae744
    30 import java.net.URI;
    30 import java.net.URI;
    31 import java.nio.ByteBuffer;
    31 import java.nio.ByteBuffer;
    32 import java.util.ArrayList;
    32 import java.util.ArrayList;
    33 import java.util.Collections;
    33 import java.util.Collections;
    34 import java.util.List;
    34 import java.util.List;
    35 import java.util.Optional;
       
    36 import java.util.concurrent.CompletableFuture;
    35 import java.util.concurrent.CompletableFuture;
    37 import java.util.concurrent.ConcurrentLinkedDeque;
    36 import java.util.concurrent.ConcurrentLinkedDeque;
    38 import java.util.concurrent.ConcurrentLinkedQueue;
    37 import java.util.concurrent.ConcurrentLinkedQueue;
    39 import java.util.concurrent.Executor;
    38 import java.util.concurrent.Executor;
    40 import java.util.concurrent.Flow;
    39 import java.util.concurrent.Flow;
    41 import java.util.concurrent.Flow.Subscription;
    40 import java.util.concurrent.Flow.Subscription;
    42 import java.util.concurrent.atomic.AtomicReference;
    41 import java.util.concurrent.atomic.AtomicReference;
       
    42 import java.util.function.BiPredicate;
    43 import jdk.incubator.http.HttpResponse.BodySubscriber;
    43 import jdk.incubator.http.HttpResponse.BodySubscriber;
    44 import jdk.incubator.http.internal.common.*;
    44 import jdk.incubator.http.internal.common.*;
    45 import jdk.incubator.http.internal.frame.*;
    45 import jdk.incubator.http.internal.frame.*;
    46 import jdk.incubator.http.internal.hpack.DecodingCallback;
    46 import jdk.incubator.http.internal.hpack.DecodingCallback;
    47 
    47 
   489             endStreamSent = true;
   489             endStreamSent = true;
   490         }
   490         }
   491         return f;
   491         return f;
   492     }
   492     }
   493 
   493 
       
   494     private boolean hasProxyAuthorization(HttpHeaders headers) {
       
   495         return headers.firstValue("proxy-authorization")
       
   496                       .isPresent();
       
   497     }
       
   498 
       
   499     // Determines whether we need to build a new HttpHeader object.
       
   500     //
       
   501     // Ideally we should pass the filter to OutgoingHeaders refactor the
       
   502     // code that creates the HeaderFrame to honor the filter.
       
   503     // We're not there yet - so depending on the filter we need to
       
   504     // apply and the content of the header we will try to determine
       
   505     //  whether anything might need to be filtered.
       
   506     // If nothing needs filtering then we can just use the
       
   507     // original headers.
       
   508     private boolean needsFiltering(HttpHeaders headers,
       
   509                                    BiPredicate<String, List<String>> filter) {
       
   510         if (filter == Utils.PROXY_TUNNEL_FILTER || filter == Utils.PROXY_FILTER) {
       
   511             // we're either connecting or proxying
       
   512             // slight optimization: we only need to filter out
       
   513             // disabled schemes, so if there are none just
       
   514             // pass through.
       
   515             return Utils.proxyHasDisabledSchemes(filter == Utils.PROXY_TUNNEL_FILTER)
       
   516                     && hasProxyAuthorization(headers);
       
   517         } else {
       
   518             // we're talking to a server, either directly or through
       
   519             // a tunnel.
       
   520             // Slight optimization: we only need to filter out
       
   521             // proxy authorization headers, so if there are none just
       
   522             // pass through.
       
   523             return hasProxyAuthorization(headers);
       
   524         }
       
   525     }
       
   526 
   494     private HttpHeaders filter(HttpHeaders headers) {
   527     private HttpHeaders filter(HttpHeaders headers) {
   495         if (connection().isTunnel()) {
   528         HttpConnection conn = connection();
   496             boolean needsFiltering = headers
   529         BiPredicate<String, List<String>> filter =
   497                     .firstValue("proxy-authorization")
   530                 conn.headerFilter(request);
   498                     .isPresent();
   531         if (needsFiltering(headers, filter)) {
   499             // don't send proxy-* headers to the target server.
   532             return ImmutableHeaders.of(headers.map(), filter);
   500             if (needsFiltering) {
       
   501                 return ImmutableHeaders.of(headers.map(),
       
   502                         Utils.NO_PROXY_HEADER);
       
   503             }
       
   504         }
   533         }
   505         return headers;
   534         return headers;
   506     }
   535     }
   507 
   536 
   508     private void setPseudoHeaderFields() {
   537     private void setPseudoHeaderFields() {