This commit is contained in:
Looly
2023-03-13 01:11:43 +08:00
parent f05e084a3b
commit 5b559d19bd
94 changed files with 320 additions and 309 deletions

View File

@@ -1,6 +1,6 @@
package cn.hutool.http;
import cn.hutool.core.codec.BaseN.Base64;
import cn.hutool.core.codec.binary.Base64;
import cn.hutool.core.net.url.UrlQueryUtil;
import cn.hutool.core.text.StrUtil;
import cn.hutool.http.client.ClientConfig;

View File

@@ -4,7 +4,6 @@ import cn.hutool.http.client.body.BytesBody;
import cn.hutool.http.client.body.HttpBody;
import org.apache.hc.core5.http.io.entity.AbstractHttpEntity;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
@@ -50,8 +49,8 @@ public class HttpClient5BodyEntity extends AbstractHttpEntity {
}
@Override
public void close() throws IOException {
public void close() {
// do nothing
}
@Override

View File

@@ -403,10 +403,6 @@ public class HttpConnection implements HeaderOperation<HttpConnection> {
final StringBuilder sb = StrUtil.builder();
sb.append("Request URL: ").append(this.url).append(StrUtil.CRLF);
sb.append("Request Method: ").append(this.getMethod()).append(StrUtil.CRLF);
// sb.append("Request Headers: ").append(StrUtil.CRLF);
// for (Entry<String, List<String>> entry : this.conn.getHeaderFields().entrySet()) {
// sb.append(" ").append(entry).append(StrUtil.CRLF);
// }
return sb.toString();
}

View File

@@ -79,7 +79,7 @@ public class JdkClientEngine implements ClientEngine {
}
@Override
public void close() throws IOException {
public void close() {
if (null != conn) {
conn.disconnectQuietly();
}

View File

@@ -1,7 +1,6 @@
package cn.hutool.http.client.engine.okhttp;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.http.client.ClientConfig;
import cn.hutool.http.client.ClientEngine;
import cn.hutool.http.client.Request;
@@ -60,8 +59,8 @@ public class OkHttpEngine implements ClientEngine {
}
@Override
public void close() throws IOException {
// ignore
public void close() {
// do nothing
}
/**

View File

@@ -7,14 +7,9 @@ import kotlin.Pair;
import okhttp3.Headers;
import okhttp3.ResponseBody;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* OkHttp3的{@link okhttp3.Response} 响应包装
@@ -74,7 +69,9 @@ public class OkHttpResponse implements Response {
}
@Override
public void close() throws IOException {
rawRes.close();
public void close() {
if(null != this.rawRes){
rawRes.close();
}
}
}

View File

@@ -201,12 +201,16 @@ public final class HTMLFilter {
}
}
// ---------------------------------------------------------------
// my versions of some PHP library functions
public static String chr(final int decimal) {
return String.valueOf((char) decimal);
}
/**
* HTML特殊字符替换
*
* @param s HTML
* @return 替换后的HTML
*/
public static String htmlSpecialChars(final String s) {
String result = s;
result = regexReplace(P_AMP, "&amp;", result);
@@ -250,10 +254,22 @@ public final class HTMLFilter {
return s;
}
/**
* flag determining whether to try to make tags when presented with "unbalanced" angle brackets (e.g. "&lt;b text &lt;/b&gt;" becomes "&lt;b&gt; text &lt;/g&gt;").
* If set to false, unbalanced angle brackets will be
* html escaped.
*
* @return alwaysMakeTags
*/
public boolean isAlwaysMakeTags() {
return alwaysMakeTags;
}
/**
* flag determining whether comments are allowed in input String.
*
* @return stripComment
*/
public boolean isStripComments() {
return stripComment;
}
@@ -364,7 +380,6 @@ public final class HTMLFilter {
final String body = m.group(2);
String ending = m.group(3);
// debug( "in a starting tag, name='" + name + "'; body='" + body + "'; ending='" + ending + "'" );
if (allowed(name)) {
final StringBuilder params = new StringBuilder();
@@ -386,10 +401,6 @@ public final class HTMLFilter {
paramName = paramNames.get(ii).toLowerCase();
paramValue = paramValues.get(ii);
// debug( "paramName='" + paramName + "'" );
// debug( "paramValue='" + paramValue + "'" );
// debug( "allowed? " + vAllowed.get( name ).contains( paramName ) );
if (allowedAttribute(name, paramName)) {
if (inArray(paramName, vProtocolAtts)) {
paramValue = processParamProtocol(paramValue);
@@ -454,7 +465,7 @@ public final class HTMLFilter {
while (m.find()) {
final String match = m.group(1);
final int decimal = Integer.decode(match);
m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
m.appendReplacement(buf, Matcher.quoteReplacement(CharUtil.toString((char) decimal)));
}
m.appendTail(buf);
s = buf.toString();
@@ -464,7 +475,7 @@ public final class HTMLFilter {
while (m.find()) {
final String match = m.group(1);
final int decimal = Integer.parseInt(match, 16);
m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
m.appendReplacement(buf, Matcher.quoteReplacement(CharUtil.toString((char) decimal)));
}
m.appendTail(buf);
s = buf.toString();
@@ -474,7 +485,7 @@ public final class HTMLFilter {
while (m.find()) {
final String match = m.group(1);
final int decimal = Integer.parseInt(match, 16);
m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
m.appendReplacement(buf, Matcher.quoteReplacement(CharUtil.toString((char) decimal)));
}
m.appendTail(buf);
s = buf.toString();

View File

@@ -1,6 +1,6 @@
package cn.hutool.http;
import cn.hutool.core.codec.BaseN.Base64;
import cn.hutool.core.codec.binary.Base64;
import cn.hutool.core.io.file.FileUtil;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.StreamProgress;