mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix name
This commit is contained in:
parent
c1a895bce5
commit
5b5209e801
@ -3,7 +3,7 @@ package cn.hutool.http.client.cookie;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.net.url.URLUtil;
|
||||
import cn.hutool.http.client.engine.jdk.HttpConnection;
|
||||
import cn.hutool.http.client.engine.jdk.JdkHttpConnection;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.CookieManager;
|
||||
@ -63,16 +63,16 @@ public class GlobalCookieManager {
|
||||
* @return Cookie信息列表
|
||||
* @since 4.6.9
|
||||
*/
|
||||
public static List<HttpCookie> getCookies(final HttpConnection conn){
|
||||
public static List<HttpCookie> getCookies(final JdkHttpConnection conn){
|
||||
return cookieManager.getCookieStore().get(getURI(conn));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将本地存储的Cookie信息附带到Http请求中,不覆盖用户定义好的Cookie
|
||||
*
|
||||
* @param conn {@link HttpConnection}
|
||||
* @param conn {@link JdkHttpConnection}
|
||||
*/
|
||||
public static void add(final HttpConnection conn) {
|
||||
public static void add(final JdkHttpConnection conn) {
|
||||
if(null == cookieManager) {
|
||||
// 全局Cookie管理器关闭
|
||||
return;
|
||||
@ -93,9 +93,9 @@ public class GlobalCookieManager {
|
||||
/**
|
||||
* 存储响应的Cookie信息到本地
|
||||
*
|
||||
* @param conn {@link HttpConnection}
|
||||
* @param conn {@link JdkHttpConnection}
|
||||
*/
|
||||
public static void store(final HttpConnection conn) {
|
||||
public static void store(final JdkHttpConnection conn) {
|
||||
store(conn, conn.headers());
|
||||
}
|
||||
|
||||
@ -103,10 +103,10 @@ public class GlobalCookieManager {
|
||||
* 存储响应的Cookie信息到本地<br>
|
||||
* 通过读取
|
||||
*
|
||||
* @param conn {@link HttpConnection}
|
||||
* @param conn {@link JdkHttpConnection}
|
||||
* @param responseHeaders 头信息Map
|
||||
*/
|
||||
public static void store(final HttpConnection conn, final Map<String, List<String>> responseHeaders) {
|
||||
public static void store(final JdkHttpConnection conn, final Map<String, List<String>> responseHeaders) {
|
||||
if(null == cookieManager || MapUtil.isEmpty(responseHeaders)) {
|
||||
// 全局Cookie管理器关闭或头信息为空
|
||||
return;
|
||||
@ -124,7 +124,7 @@ public class GlobalCookieManager {
|
||||
* @param conn HttpConnection
|
||||
* @return URI
|
||||
*/
|
||||
private static URI getURI(final HttpConnection conn){
|
||||
private static URI getURI(final JdkHttpConnection conn){
|
||||
return URLUtil.toURI(conn.getUrl());
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ import java.net.HttpURLConnection;
|
||||
public class JdkClientEngine implements ClientEngine {
|
||||
|
||||
private ClientConfig config;
|
||||
private HttpConnection conn;
|
||||
private JdkHttpConnection conn;
|
||||
/**
|
||||
* 重定向次数计数器,内部使用
|
||||
*/
|
||||
@ -60,7 +60,7 @@ public class JdkClientEngine implements ClientEngine {
|
||||
* @param isAsync 是否异步,异步不会立即读取响应内容
|
||||
* @return {@link Response}
|
||||
*/
|
||||
public HttpResponse send(final Request message, final boolean isAsync) {
|
||||
public JdkHttpResponse send(final Request message, final boolean isAsync) {
|
||||
initConn(message);
|
||||
try {
|
||||
doSend(message);
|
||||
@ -116,15 +116,15 @@ public class JdkClientEngine implements ClientEngine {
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建{@link HttpConnection}
|
||||
* 构建{@link JdkHttpConnection}
|
||||
*
|
||||
* @param message {@link Request}消息
|
||||
* @return {@link HttpConnection}
|
||||
* @return {@link JdkHttpConnection}
|
||||
*/
|
||||
private HttpConnection buildConn(final Request message) {
|
||||
private JdkHttpConnection buildConn(final Request message) {
|
||||
final ClientConfig config = ObjUtil.defaultIfNull(this.config, ClientConfig::of);
|
||||
|
||||
final HttpConnection conn = HttpConnection
|
||||
final JdkHttpConnection conn = JdkHttpConnection
|
||||
.of(message.url().toURL(), config.getProxy())
|
||||
.setConnectTimeout(config.getConnectionTimeout())
|
||||
.setReadTimeout(config.getReadTimeout())
|
||||
@ -149,10 +149,10 @@ public class JdkClientEngine implements ClientEngine {
|
||||
* 调用转发,如果需要转发返回转发结果,否则返回{@code null}
|
||||
*
|
||||
* @param isAsync 最终请求是否异步
|
||||
* @return {@link HttpResponse},无转发返回 {@code null}
|
||||
* @return {@link JdkHttpResponse},无转发返回 {@code null}
|
||||
*/
|
||||
private HttpResponse sendRedirectIfPossible(final Request message, final boolean isAsync) {
|
||||
final HttpConnection conn = this.conn;
|
||||
private JdkHttpResponse sendRedirectIfPossible(final Request message, final boolean isAsync) {
|
||||
final JdkHttpConnection conn = this.conn;
|
||||
// 手动实现重定向
|
||||
if (message.maxRedirectCount() > 0) {
|
||||
final int code;
|
||||
@ -176,7 +176,7 @@ public class JdkClientEngine implements ClientEngine {
|
||||
}
|
||||
|
||||
// 最终页面
|
||||
return new HttpResponse(this.conn, true, message.charset(), isAsync,
|
||||
return new JdkHttpResponse(this.conn, true, message.charset(), isAsync,
|
||||
isIgnoreResponseBody(message.method()));
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ import java.util.Map;
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public class HttpConnection implements HeaderOperation<HttpConnection> {
|
||||
public class JdkHttpConnection implements HeaderOperation<JdkHttpConnection> {
|
||||
|
||||
private final URL url;
|
||||
private final Proxy proxy;
|
||||
@ -38,7 +38,7 @@ public class HttpConnection implements HeaderOperation<HttpConnection> {
|
||||
* @param proxy 代理,无代理传{@code null}
|
||||
* @return HttpConnection
|
||||
*/
|
||||
public static HttpConnection of(final String urlStr, final Proxy proxy) {
|
||||
public static JdkHttpConnection of(final String urlStr, final Proxy proxy) {
|
||||
return of(URLUtil.toUrlForHttp(urlStr), proxy);
|
||||
}
|
||||
|
||||
@ -49,8 +49,8 @@ public class HttpConnection implements HeaderOperation<HttpConnection> {
|
||||
* @param proxy 代理,无代理传{@code null}
|
||||
* @return HttpConnection
|
||||
*/
|
||||
public static HttpConnection of(final URL url, final Proxy proxy) {
|
||||
return new HttpConnection(url, proxy);
|
||||
public static JdkHttpConnection of(final URL url, final Proxy proxy) {
|
||||
return new JdkHttpConnection(url, proxy);
|
||||
}
|
||||
|
||||
// region --------------------------------------------------------------- Constructor
|
||||
@ -61,7 +61,7 @@ public class HttpConnection implements HeaderOperation<HttpConnection> {
|
||||
* @param url URL
|
||||
* @param proxy 代理
|
||||
*/
|
||||
public HttpConnection(final URL url, final Proxy proxy) {
|
||||
public JdkHttpConnection(final URL url, final Proxy proxy) {
|
||||
this.url = url;
|
||||
this.proxy = proxy;
|
||||
|
||||
@ -90,7 +90,7 @@ public class HttpConnection implements HeaderOperation<HttpConnection> {
|
||||
* @param method 请求方法
|
||||
* @return 自己
|
||||
*/
|
||||
public HttpConnection setMethod(final Method method) {
|
||||
public JdkHttpConnection setMethod(final Method method) {
|
||||
if (Method.POST.equals(method) //
|
||||
|| Method.PUT.equals(method)//
|
||||
|| Method.PATCH.equals(method)//
|
||||
@ -147,7 +147,7 @@ public class HttpConnection implements HeaderOperation<HttpConnection> {
|
||||
* @return this
|
||||
* @see HttpURLConnection#setUseCaches(boolean)
|
||||
*/
|
||||
public HttpConnection setDisableCache(final boolean isDisableCache) {
|
||||
public JdkHttpConnection setDisableCache(final boolean isDisableCache) {
|
||||
this.conn.setUseCaches(!isDisableCache);
|
||||
return this;
|
||||
}
|
||||
@ -158,7 +158,7 @@ public class HttpConnection implements HeaderOperation<HttpConnection> {
|
||||
* @param timeout 超时
|
||||
* @return this
|
||||
*/
|
||||
public HttpConnection setConnectTimeout(final int timeout) {
|
||||
public JdkHttpConnection setConnectTimeout(final int timeout) {
|
||||
if (timeout > 0 && null != this.conn) {
|
||||
this.conn.setConnectTimeout(timeout);
|
||||
}
|
||||
@ -172,7 +172,7 @@ public class HttpConnection implements HeaderOperation<HttpConnection> {
|
||||
* @param timeout 超时
|
||||
* @return this
|
||||
*/
|
||||
public HttpConnection setReadTimeout(final int timeout) {
|
||||
public JdkHttpConnection setReadTimeout(final int timeout) {
|
||||
if (timeout > 0 && null != this.conn) {
|
||||
this.conn.setReadTimeout(timeout);
|
||||
}
|
||||
@ -186,7 +186,7 @@ public class HttpConnection implements HeaderOperation<HttpConnection> {
|
||||
* @param timeout 超时时间
|
||||
* @return this
|
||||
*/
|
||||
public HttpConnection setConnectionAndReadTimeout(final int timeout) {
|
||||
public JdkHttpConnection setConnectionAndReadTimeout(final int timeout) {
|
||||
setConnectTimeout(timeout);
|
||||
setReadTimeout(timeout);
|
||||
|
||||
@ -202,7 +202,7 @@ public class HttpConnection implements HeaderOperation<HttpConnection> {
|
||||
* @throws HttpException KeyManagementException和NoSuchAlgorithmException异常包装
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public HttpConnection setSSLInfo(final SSLInfo sslInfo) throws HttpException {
|
||||
public JdkHttpConnection setSSLInfo(final SSLInfo sslInfo) throws HttpException {
|
||||
final HttpURLConnection conn = this.conn;
|
||||
|
||||
if (conn instanceof HttpsURLConnection) {
|
||||
@ -223,7 +223,7 @@ public class HttpConnection implements HeaderOperation<HttpConnection> {
|
||||
* @param blockSize 块大小(bytes数),0或小于0表示不设置Chuncked模式
|
||||
* @return this
|
||||
*/
|
||||
public HttpConnection setChunkedStreamingMode(final int blockSize) {
|
||||
public JdkHttpConnection setChunkedStreamingMode(final int blockSize) {
|
||||
if (blockSize > 0) {
|
||||
conn.setChunkedStreamingMode(blockSize);
|
||||
}
|
||||
@ -236,7 +236,7 @@ public class HttpConnection implements HeaderOperation<HttpConnection> {
|
||||
* @param isInstanceFollowRedirects 是否自定跳转
|
||||
* @return this
|
||||
*/
|
||||
public HttpConnection setInstanceFollowRedirects(final boolean isInstanceFollowRedirects) {
|
||||
public JdkHttpConnection setInstanceFollowRedirects(final boolean isInstanceFollowRedirects) {
|
||||
conn.setInstanceFollowRedirects(isInstanceFollowRedirects);
|
||||
return this;
|
||||
}
|
||||
@ -255,7 +255,7 @@ public class HttpConnection implements HeaderOperation<HttpConnection> {
|
||||
* @return HttpConnection
|
||||
*/
|
||||
@Override
|
||||
public HttpConnection header(final String header, final String value, final boolean isOverride) {
|
||||
public JdkHttpConnection header(final String header, final String value, final boolean isOverride) {
|
||||
if (null != this.conn) {
|
||||
if (isOverride) {
|
||||
this.conn.setRequestProperty(header, value);
|
||||
@ -296,7 +296,7 @@ public class HttpConnection implements HeaderOperation<HttpConnection> {
|
||||
* @return this
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
public HttpConnection connect() throws IOException {
|
||||
public JdkHttpConnection connect() throws IOException {
|
||||
if (null != this.conn) {
|
||||
this.conn.connect();
|
||||
}
|
||||
@ -309,7 +309,7 @@ public class HttpConnection implements HeaderOperation<HttpConnection> {
|
||||
* @return this
|
||||
* @since 4.6.0
|
||||
*/
|
||||
public HttpConnection disconnectQuietly() {
|
||||
public JdkHttpConnection disconnectQuietly() {
|
||||
try {
|
||||
disconnect();
|
||||
} catch (final Throwable e) {
|
||||
@ -324,7 +324,7 @@ public class HttpConnection implements HeaderOperation<HttpConnection> {
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public HttpConnection disconnect() {
|
||||
public JdkHttpConnection disconnect() {
|
||||
if (null != this.conn) {
|
||||
this.conn.disconnect();
|
||||
}
|
@ -16,7 +16,7 @@ import java.io.InputStream;
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public class HttpInputStream extends InputStream {
|
||||
public class JdkHttpInputStream extends InputStream {
|
||||
|
||||
/**
|
||||
* 原始流
|
||||
@ -28,7 +28,7 @@ public class HttpInputStream extends InputStream {
|
||||
*
|
||||
* @param response 响应对象
|
||||
*/
|
||||
public HttpInputStream(final HttpResponse response) {
|
||||
public JdkHttpInputStream(final JdkHttpResponse response) {
|
||||
init(response);
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ public class HttpInputStream extends InputStream {
|
||||
*
|
||||
* @param response 响应对象
|
||||
*/
|
||||
private void init(final HttpResponse response) {
|
||||
private void init(final JdkHttpResponse response) {
|
||||
try {
|
||||
this.in = (response.status < HttpStatus.HTTP_BAD_REQUEST) ? response.httpConnection.getInputStream() : response.httpConnection.getErrorStream();
|
||||
} catch (final IOException e) {
|
@ -27,7 +27,7 @@ import java.util.Map.Entry;
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public class HttpResponse implements Response, Closeable {
|
||||
public class JdkHttpResponse implements Response, Closeable {
|
||||
|
||||
/**
|
||||
* 请求时的默认编码
|
||||
@ -49,7 +49,7 @@ public class HttpResponse implements Response, Closeable {
|
||||
/**
|
||||
* 持有连接对象
|
||||
*/
|
||||
protected HttpConnection httpConnection;
|
||||
protected JdkHttpConnection httpConnection;
|
||||
/**
|
||||
* 响应状态码
|
||||
*/
|
||||
@ -58,13 +58,13 @@ public class HttpResponse implements Response, Closeable {
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param httpConnection {@link HttpConnection}
|
||||
* @param httpConnection {@link JdkHttpConnection}
|
||||
* @param ignoreEOFError 是否忽略响应读取时可能的EOF异常
|
||||
* @param requestCharset 编码,从请求编码中获取默认编码
|
||||
* @param isAsync 是否异步
|
||||
* @param isIgnoreBody 是否忽略读取响应体
|
||||
*/
|
||||
protected HttpResponse(final HttpConnection httpConnection, final boolean ignoreEOFError, final Charset requestCharset, final boolean isAsync, final boolean isIgnoreBody) {
|
||||
protected JdkHttpResponse(final JdkHttpConnection httpConnection, final boolean ignoreEOFError, final Charset requestCharset, final boolean isAsync, final boolean isIgnoreBody) {
|
||||
this.httpConnection = httpConnection;
|
||||
this.ignoreEOFError = ignoreEOFError;
|
||||
this.requestCharset = requestCharset;
|
||||
@ -112,7 +112,7 @@ public class HttpResponse implements Response, Closeable {
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public HttpResponse sync() {
|
||||
public JdkHttpResponse sync() {
|
||||
if (null != this.body) {
|
||||
this.body.sync();
|
||||
}
|
||||
@ -259,7 +259,7 @@ public class HttpResponse implements Response, Closeable {
|
||||
|
||||
// 获取响应内容流
|
||||
if (false == isIgnoreBody) {
|
||||
this.body = new ResponseBody(this, new HttpInputStream(this), isAsync, this.ignoreEOFError);
|
||||
this.body = new ResponseBody(this, new JdkHttpInputStream(this), isAsync, this.ignoreEOFError);
|
||||
}
|
||||
}
|
||||
// ---------------------------------------------------------------- Private method end
|
@ -29,7 +29,7 @@ public class HtmlUtil {
|
||||
/**
|
||||
* script标签正则
|
||||
*/
|
||||
public static final Pattern RE_SCRIPT = Pattern.compile("<[\\s]*?script[^>]*?>.*?<[\\s]*?\\/[\\s]*?script[\\s]*?>", Pattern.CASE_INSENSITIVE);
|
||||
public static final Pattern RE_SCRIPT = Pattern.compile("<\\s*?script[^>]*?>.*?<\\s*?/\\s*?script\\s*?>", Pattern.CASE_INSENSITIVE);
|
||||
/**
|
||||
* 正则:匹配meta标签的编码信息
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user