Http Client 源碼分析


/**
* 此接口僅代表HTTP請求執行的最基本約定。
* 它對請求執行過程沒有任何限制或特定的細節,並將狀態管理、身份驗證和重定向處理的細節留給單個實現。
*/
public interface HttpClient {
HttpResponse execute(HttpUriRequest request);
}


/**
* 用於提供創建{@link CloseableHttpClient}實例工廠方法.
*/
public class HttpClients {
public static CloseableHttpClient createDefault() {
return HttpClientBuilder.create().build();
}
}


/**
* HTTP消息 包括從客戶機到服務器的請求和從服務器到客戶機的響應。
* HTTP-message = Request | Response ; HTTP/1.1 messages
* 
* {@link HttpRequest} and {@link HttpResponse} 接口繼承{@link HttpMessage }
*/
public interface HttpMessage {
}


/**
* 從客戶機到服務器的請求消息包括,
* 在該消息的第一行中,要應用於該資源的方法、資源的標識符以及正在使用的協議版本。
* method uri http/1.1
*/
public interface HttpRequest extends HttpMessage {
RequestLine getRequestLine(); // 獲取請求行
}


/**
* 在接收和解釋請求消息后,服務器用HTTP響應消息響應。
* 設置/獲取 狀態行、狀態碼、原因短語、實體、locale
*/
public interface HttpResponse extends HttpMessage {
}


/**
* Extended version of the {@link HttpRequest} interface that provides convenience methods to access request properties such as request URI and method type.
* {@link HttpRequest}接口的擴展版本,提供訪問請求屬性(如請求URI和方法類型)的方便方法。
*/
public interface HttpUriRequest extends HttpRequest {
String getMethod();
URI getURI();
void abort() ; // 中止請求的執行.
boolean isAborted();
}


/**
* {@link HttpUriRequest}的基本實現.
*/
public abstract class HttpRequestBase extends AbstractExecutionAwareRequest implements HttpUriRequest, Configurable {
private ProtocolVersion version;
private URI uri;
private RequestConfig config;
}


/**
* {@link HttpClient}的基本實現,也實現{@link Closeable}。
*/
@Contract(threading = ThreadingBehavior.SAFE)
public abstract class CloseableHttpClient implements HttpClient, Closeable {
// 只有多個重載的execute()方法、用於執行請求、
// 使用默認上下文執行請求,並使用給定的響應處理程序處理響應。

}


/**
* {@code Closeable}是可以關閉的數據源或目標.
* 調用close方法釋放對象所持有的資源(如打開的文件).
*/
public interface Closeable extends AutoCloseable {
}


/**
* HTTP GET method.
* GET方法意味着檢索請求URI標識的任何信息(以實體的形式)。
* 通過分析給定的字符串創建URI。
*/
public class HttpGet extends HttpRequestBase {

}


/**
* HTTP POST method.
* POST方法用於請求源服務器接受請求中包含的實體作為請求行中請求URI標識的資源的新下屬。
*/
public class HttpPost extends HttpEntityEnclosingRequestBase {

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM