Ejemplo n.º 1
0
      private void tunnel(HttpDestination destination, final Connection connection) {
        String target = destination.getOrigin().getAddress().asString();
        Origin.Address proxyAddress = destination.getConnectAddress();
        HttpClient httpClient = destination.getHttpClient();
        Request connect =
            httpClient
                .newRequest(proxyAddress.getHost(), proxyAddress.getPort())
                .scheme(HttpScheme.HTTP.asString())
                .method(HttpMethod.CONNECT)
                .path(target)
                .header(HttpHeader.HOST, target)
                .timeout(httpClient.getConnectTimeout(), TimeUnit.MILLISECONDS);

        connection.send(
            connect,
            new Response.CompleteListener() {
              @Override
              public void onComplete(Result result) {
                if (result.isFailed()) {
                  tunnelFailed(result.getFailure());
                } else {
                  Response response = result.getResponse();
                  if (response.getStatus() == 200) {
                    tunnelSucceeded();
                  } else {
                    tunnelFailed(
                        new HttpResponseException(
                            "Received " + response + " for " + result.getRequest(), response));
                  }
                }
              }
            });
      }
 private void tunnel(final Connection connection) {
   String target = address.getHost() + ":" + address.getPort();
   Request connect =
       client
           .newRequest(proxyAddress.getHost(), proxyAddress.getPort())
           .scheme(HttpScheme.HTTP.asString())
           .method(HttpMethod.CONNECT)
           .path(target)
           .header(HttpHeader.HOST.asString(), target)
           .timeout(client.getConnectTimeout(), TimeUnit.MILLISECONDS);
   connection.send(
       connect,
       new Response.CompleteListener() {
         @Override
         public void onComplete(Result result) {
           if (result.isFailed()) {
             failed(result.getFailure());
             connection.close();
           } else {
             Response response = result.getResponse();
             if (response.getStatus() == 200) {
               delegate.succeeded(connection);
             } else {
               failed(
                   new HttpResponseException(
                       "Received " + response + " for " + result.getRequest(), response));
               connection.close();
             }
           }
         }
       });
 }
Ejemplo n.º 3
0
 @Override
 public URI getURI() {
   String scheme = isSecure() ? HttpScheme.HTTPS.asString() : HttpScheme.HTTP.asString();
   return URI.create(new Origin(scheme, getAddress()).asString());
 }