Java 类com.facebook.stetho.urlconnection.StethoURLConnectionManager 实例源码

项目:Stetho-Volley    文件:StethoVolleyStack.java   
private boolean addBodyIfExists(StethoURLConnectionManager connectionManager, HttpURLConnection connection, Request<?> request)
        throws IOException, AuthFailureError {
    byte[] body = request.getBody();
    if (body != null) {
        connection.setDoOutput(true);
        connection.addRequestProperty("Content-Type", request.getBodyContentType());

        connectionManager.preConnect(connection, formRequestEntity(body));

        DataOutputStream out = new DataOutputStream(connection.getOutputStream());
        out.write(body);
        out.close();
        return true;
    }
    return false;
}
项目:Stetho-Volley    文件:StethoVolleyStack.java   
private void postConnect(StethoURLConnectionManager manager) {
    try {
        manager.postConnect();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:Stetho-Volley    文件:StethoVolleyStack.java   
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError {

    String friendlyName = System.currentTimeMillis() + "";
    StethoURLConnectionManager connectionManager = new StethoURLConnectionManager(friendlyName);

    String urlString = request.getUrl();
    HashMap<String, String> map = new HashMap<String, String>();
    map.putAll(request.getHeaders());
    map.putAll(additionalHeaders);

    URL url = new URL(urlString);

    HttpURLConnection connection = openConnection(url, request);

    for (String headerName : map.keySet()) {
        connection.addRequestProperty(headerName, map.get(headerName));
    }
    connection.addRequestProperty("Accept-Encoding","gzip");
    boolean isPreConnected = setConnectionParametersForRequest(connectionManager, connection, request);

    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);

    if (!isPreConnected) {
        preConnect(connectionManager,connection,null);
    }

    int responseCode = connection.getResponseCode();
    if (responseCode == -1) {
        throw new IOException("Could not retrieve response code from HttpUrlConnection.");
    }

    StatusLine responseStatus = new BasicStatusLine(protocolVersion,
            connection.getResponseCode(), connection.getResponseMessage());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);

    postConnect(connectionManager);

    if (hasResponseBody(request.getMethod(), responseStatus.getStatusCode())) {
        response.setEntity(entityFromConnection(connection));
    }
    for (Map.Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) {
        if (header.getKey() != null) {
            Header h = new BasicHeader(header.getKey(), header.getValue().get(0));
            response.addHeader(h);
        }
    }

    return response;
}
项目:Stetho-Volley    文件:StethoVolleyStack.java   
private void preConnect(StethoURLConnectionManager manager, HttpURLConnection connection, SimpleRequestEntity requestEntity) {
    manager.preConnect(connection, requestEntity);
}
项目:Stetho-Volley    文件:StethoVolleyStack.java   
private boolean setConnectionParametersForRequest(StethoURLConnectionManager connectionManager, HttpURLConnection connection,
                                              Request<?> request) throws IOException, AuthFailureError {
    switch (request.getMethod()) {
        case Request.Method.DEPRECATED_GET_OR_POST:
            byte[] postBody = request.getPostBody();
            if (postBody != null) {
                connection.setDoOutput(true);
                connection.setRequestMethod("POST");
                connection.addRequestProperty("Content-Type", request.getPostBodyContentType());

                preConnect(connectionManager, connection, null);

                DataOutputStream out = new DataOutputStream(connection.getOutputStream());
                out.write(postBody);
                out.close();
            }
            return true;
        case Request.Method.GET:
            connection.setRequestMethod("GET");
            return false;
        case Request.Method.DELETE:
            connection.setRequestMethod("DELETE");
            return false;
        case Request.Method.POST:
            connection.setRequestMethod("POST");
            return addBodyIfExists(connectionManager, connection, request);
        case Request.Method.PUT:
            connection.setRequestMethod("PUT");
            return addBodyIfExists(connectionManager, connection, request);
        case Request.Method.HEAD:
            connection.setRequestMethod("HEAD");
            return false;
        case Request.Method.OPTIONS:
            connection.setRequestMethod("OPTIONS");
            return false;
        case Request.Method.TRACE:
            connection.setRequestMethod("TRACE");
            return false;
        case Request.Method.PATCH:
            connection.setRequestMethod("PATCH");
            return addBodyIfExists(connectionManager, connection, request);
        default:
            throw new IllegalStateException("Unknown method type.");
    }
}
项目:glide-support    文件:StethoHttpUrlFetcher.java   
public StethoHttpUrlFetcher(GlideUrl glideUrl) {
    this.glideUrl = glideUrl;
    this.stethoManager = new StethoURLConnectionManager("Glide");
}
项目:stetho    文件:Networker.java   
public HttpRequestTask(HttpRequest request, Callback callback) {
  this.request = request;
  this.callback = callback;
  stethoManager = new StethoURLConnectionManager(request.friendlyName);
}
项目:asstudydemo    文件:Networker.java   
public HttpRequestTask(HttpRequest request, Callback callback) {
    this.request = request;
    this.callback = callback;
    stethoManager = new StethoURLConnectionManager(request.friendlyName);
}