コード例 #1
0
ファイル: HttpEngine.java プロジェクト: gdkjrygh/CompSecurity
 private Request networkRequest(Request request)
 {
     com.squareup.okhttp.Request.Builder builder = request.newBuilder();
     if (request.header("Host") == null)
     {
         builder.header("Host", Util.hostHeader(request.httpUrl()));
     }
     if ((connection == null || connection.getProtocol() != Protocol.HTTP_1_0) && request.header("Connection") == null)
     {
         builder.header("Connection", "Keep-Alive");
     }
     if (request.header("Accept-Encoding") == null)
     {
         transparentGzip = true;
         builder.header("Accept-Encoding", "gzip");
     }
     CookieHandler cookiehandler = client.getCookieHandler();
     if (cookiehandler != null)
     {
         java.util.Map map = OkHeaders.toMultimap(builder.build().headers(), null);
         OkHeaders.addCookies(builder, cookiehandler.get(request.uri(), map));
     }
     if (request.header("User-Agent") == null)
     {
         builder.header("User-Agent", Version.userAgent());
     }
     return builder.build();
 }
コード例 #2
0
  @Override
  protected HttpResponse invoke(Request nativeRequest) throws IOException, InterruptedException {
    OkHttpClient requestScopedClient = globalClient.clone();
    requestScopedClient.setProxy(proxyForURI.apply(nativeRequest.uri()));

    Response response = requestScopedClient.newCall(nativeRequest).execute();

    HttpResponse.Builder<?> builder = HttpResponse.builder();
    builder.statusCode(response.code());
    builder.message(response.message());

    Builder<String, String> headerBuilder = ImmutableMultimap.builder();
    Headers responseHeaders = response.headers();
    for (String header : responseHeaders.names()) {
      headerBuilder.putAll(header, responseHeaders.values(header));
    }

    ImmutableMultimap<String, String> headers = headerBuilder.build();

    if (response.code() == 204 && response.body() != null) {
      response.body().close();
    } else {
      Payload payload = newInputStreamPayload(response.body().byteStream());
      contentMetadataCodec.fromHeaders(payload.getContentMetadata(), headers);
      builder.payload(payload);
    }

    builder.headers(filterOutContentHeaders(headers));

    return builder.build();
  }
コード例 #3
0
ファイル: RouteSelector.java プロジェクト: Gongcong/okhttp
  public static RouteSelector get(Request request, OkHttpClient client, Dns dns)
      throws IOException {
    String uriHost = request.url().getHost();
    if (uriHost == null || uriHost.length() == 0) {
      throw new UnknownHostException(request.url().toString());
    }

    SSLSocketFactory sslSocketFactory = null;
    HostnameVerifier hostnameVerifier = null;
    if (request.isHttps()) {
      sslSocketFactory = client.getSslSocketFactory();
      hostnameVerifier = client.getHostnameVerifier();
    }

    Address address =
        new Address(
            uriHost,
            getEffectivePort(request.url()),
            client.getSocketFactory(),
            sslSocketFactory,
            hostnameVerifier,
            client.getAuthenticator(),
            client.getProxy(),
            client.getProtocols());

    return new RouteSelector(address, request.uri(), dns, client, request);
  }
コード例 #4
0
  protected String get(String url) throws IOException, ApiException, JSONException {

    String responseString = "";

    OkHttpClient client = new OkHttpClient();

    Request request = new Request.Builder().url(url).build();

    Response response = client.newCall(request).execute();
    responseString = response.body().string();

    if (!response.isSuccessful()) {
      handleError(response.code(), request.uri() + "", responseString);
    }

    return responseString;
  }
コード例 #5
0
ファイル: RouteSelector.java プロジェクト: deveshmittal/hike
 public static RouteSelector get(Address address, Request request, OkHttpClient client)
     throws IOException {
   return new RouteSelector(address, request.uri(), client, request);
 }