mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -24,7 +24,7 @@ public enum ContentType {
|
||||
TEXT_XML("text/xml");
|
||||
|
||||
private String value;
|
||||
private ContentType(String value) {
|
||||
ContentType(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
@@ -26,7 +26,7 @@ public enum GlobalHeaders {
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
private GlobalHeaders() {
|
||||
GlobalHeaders() {
|
||||
putDefault(false);
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ public enum GlobalHeaders {
|
||||
if (null != name && null != value) {
|
||||
final List<String> values = headers.get(name.trim());
|
||||
if (isOverride || CollectionUtil.isEmpty(values)) {
|
||||
final ArrayList<String> valueList = new ArrayList<String>();
|
||||
final ArrayList<String> valueList = new ArrayList<>();
|
||||
valueList.add(value);
|
||||
headers.put(name.trim(), valueList);
|
||||
} else {
|
||||
|
@@ -64,7 +64,7 @@ public enum Header {
|
||||
LOCATION("Location");
|
||||
|
||||
private String value;
|
||||
private Header(String value) {
|
||||
Header(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
@@ -21,6 +21,7 @@ import javax.net.ssl.SSLSocketFactory;
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.resource.BytesResource;
|
||||
import cn.hutool.core.io.resource.FileResource;
|
||||
@@ -811,11 +812,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @since 3.3.0
|
||||
*/
|
||||
public HttpRequest setMaxRedirectCount(int maxRedirectCount) {
|
||||
if (maxRedirectCount > 0) {
|
||||
this.maxRedirectCount = maxRedirectCount;
|
||||
} else {
|
||||
this.maxRedirectCount = 0;
|
||||
}
|
||||
this.maxRedirectCount = Math.max(maxRedirectCount, 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -993,7 +990,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
// 自定义Cookie
|
||||
.setCookie(this.cookie)
|
||||
// 定义转发
|
||||
.setInstanceFollowRedirects(this.maxRedirectCount > 0 ? true : false)
|
||||
.setInstanceFollowRedirects(this.maxRedirectCount > 0)
|
||||
// 流方式上传数据
|
||||
.setChunkedStreamingMode(this.blockSize)
|
||||
// 覆盖默认Header
|
||||
@@ -1060,9 +1057,9 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
/**
|
||||
* 发送数据流
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
private void send() throws HttpException {
|
||||
private void send() throws IORuntimeException {
|
||||
try {
|
||||
if (Method.POST.equals(this.method) || Method.PUT.equals(this.method) || Method.DELETE.equals(this.method) || this.isRest) {
|
||||
if (CollectionUtil.isEmpty(this.fileForm)) {
|
||||
@@ -1076,7 +1073,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
} catch (IOException e) {
|
||||
// 异常时关闭连接
|
||||
this.httpConnection.disconnectQuietly();
|
||||
throw new HttpException(e);
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1084,7 +1081,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* 发送普通表单<br>
|
||||
* 发送数据后自动关闭输出流
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
private void sendFormUrlEncoded() throws IOException {
|
||||
if (StrUtil.isBlank(this.header(Header.CONTENT_TYPE))) {
|
||||
@@ -1105,7 +1102,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* 发送多组件请求(例如包含文件的表单)<br>
|
||||
* 发送数据后自动关闭输出流
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
private void sendMultipart() throws IOException {
|
||||
setMultipart();// 设置表单类型为Multipart
|
||||
@@ -1114,8 +1111,6 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
writeFileForm(out);
|
||||
writeForm(out);
|
||||
formEnd(out);
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1125,9 +1120,8 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* 发送普通表单内容
|
||||
*
|
||||
* @param out 输出流
|
||||
* @throws IOException
|
||||
*/
|
||||
private void writeForm(OutputStream out) throws IOException {
|
||||
private void writeForm(OutputStream out) {
|
||||
if (CollectionUtil.isNotEmpty(this.form)) {
|
||||
StringBuilder builder = StrUtil.builder();
|
||||
for (Entry<String, Object> entry : this.form.entrySet()) {
|
||||
@@ -1143,9 +1137,8 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* 发送文件对象表单
|
||||
*
|
||||
* @param out 输出流
|
||||
* @throws IOException
|
||||
*/
|
||||
private void writeFileForm(OutputStream out) throws IOException {
|
||||
private void writeFileForm(OutputStream out) {
|
||||
for (Entry<String, Resource> entry : this.fileForm.entrySet()) {
|
||||
appendPart(entry.getKey(), entry.getValue(), out);
|
||||
}
|
||||
@@ -1191,7 +1184,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* 上传表单结束
|
||||
*
|
||||
* @param out 输出流
|
||||
* @throws IOException
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
private void formEnd(OutputStream out) throws IOException {
|
||||
out.write(BOUNDARY_END);
|
||||
@@ -1201,7 +1194,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
/**
|
||||
* 设置表单类型为Multipart(文件上传)
|
||||
*
|
||||
* @return HttpConnection
|
||||
* @return HttpConnection HTTP连接对象
|
||||
*/
|
||||
private void setMultipart() {
|
||||
this.httpConnection.header(Header.CONTENT_TYPE, CONTENT_TYPE_MULTIPART_PREFIX + BOUNDARY, true);
|
||||
@@ -1215,10 +1208,10 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @since 3.1.2
|
||||
*/
|
||||
private boolean isIgnoreResponseBody() {
|
||||
if (Method.HEAD == this.method || Method.CONNECT == this.method || Method.OPTIONS == this.method || Method.TRACE == this.method) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return Method.HEAD == this.method //
|
||||
|| Method.CONNECT == this.method //
|
||||
|| Method.OPTIONS == this.method //
|
||||
|| Method.TRACE == this.method;
|
||||
}
|
||||
// ---------------------------------------------------------------- Private method end
|
||||
|
||||
|
@@ -6,5 +6,5 @@ package cn.hutool.http;
|
||||
*
|
||||
*/
|
||||
public enum Method {
|
||||
GET, POST, HEAD, OPTIONS, PUT, DELETE, TRACE, CONNECT, PATCH;
|
||||
GET, POST, HEAD, OPTIONS, PUT, DELETE, TRACE, CONNECT, PATCH
|
||||
}
|
||||
|
@@ -5,185 +5,185 @@ package cn.hutool.http;
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
public interface Status {
|
||||
interface Status {
|
||||
/**
|
||||
* HTTP Status-Code 200: OK.
|
||||
*/
|
||||
public static final int HTTP_OK = 200;
|
||||
int HTTP_OK = 200;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 201: Created.
|
||||
*/
|
||||
public static final int HTTP_CREATED = 201;
|
||||
int HTTP_CREATED = 201;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 202: Accepted.
|
||||
*/
|
||||
public static final int HTTP_ACCEPTED = 202;
|
||||
int HTTP_ACCEPTED = 202;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 203: Non-Authoritative Information.
|
||||
*/
|
||||
public static final int HTTP_NOT_AUTHORITATIVE = 203;
|
||||
int HTTP_NOT_AUTHORITATIVE = 203;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 204: No Content.
|
||||
*/
|
||||
public static final int HTTP_NO_CONTENT = 204;
|
||||
int HTTP_NO_CONTENT = 204;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 205: Reset Content.
|
||||
*/
|
||||
public static final int HTTP_RESET = 205;
|
||||
int HTTP_RESET = 205;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 206: Partial Content.
|
||||
*/
|
||||
public static final int HTTP_PARTIAL = 206;
|
||||
int HTTP_PARTIAL = 206;
|
||||
|
||||
/* 3XX: relocation/redirect */
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 300: Multiple Choices.
|
||||
*/
|
||||
public static final int HTTP_MULT_CHOICE = 300;
|
||||
int HTTP_MULT_CHOICE = 300;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 301: Moved Permanently.
|
||||
*/
|
||||
public static final int HTTP_MOVED_PERM = 301;
|
||||
int HTTP_MOVED_PERM = 301;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 302: Temporary Redirect.
|
||||
*/
|
||||
public static final int HTTP_MOVED_TEMP = 302;
|
||||
int HTTP_MOVED_TEMP = 302;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 303: See Other.
|
||||
*/
|
||||
public static final int HTTP_SEE_OTHER = 303;
|
||||
int HTTP_SEE_OTHER = 303;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 304: Not Modified.
|
||||
*/
|
||||
public static final int HTTP_NOT_MODIFIED = 304;
|
||||
int HTTP_NOT_MODIFIED = 304;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 305: Use Proxy.
|
||||
*/
|
||||
public static final int HTTP_USE_PROXY = 305;
|
||||
int HTTP_USE_PROXY = 305;
|
||||
|
||||
/* 4XX: client error */
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 400: Bad Request.
|
||||
*/
|
||||
public static final int HTTP_BAD_REQUEST = 400;
|
||||
int HTTP_BAD_REQUEST = 400;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 401: Unauthorized.
|
||||
*/
|
||||
public static final int HTTP_UNAUTHORIZED = 401;
|
||||
int HTTP_UNAUTHORIZED = 401;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 402: Payment Required.
|
||||
*/
|
||||
public static final int HTTP_PAYMENT_REQUIRED = 402;
|
||||
int HTTP_PAYMENT_REQUIRED = 402;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 403: Forbidden.
|
||||
*/
|
||||
public static final int HTTP_FORBIDDEN = 403;
|
||||
int HTTP_FORBIDDEN = 403;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 404: Not Found.
|
||||
*/
|
||||
public static final int HTTP_NOT_FOUND = 404;
|
||||
int HTTP_NOT_FOUND = 404;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 405: Method Not Allowed.
|
||||
*/
|
||||
public static final int HTTP_BAD_METHOD = 405;
|
||||
int HTTP_BAD_METHOD = 405;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 406: Not Acceptable.
|
||||
*/
|
||||
public static final int HTTP_NOT_ACCEPTABLE = 406;
|
||||
int HTTP_NOT_ACCEPTABLE = 406;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 407: Proxy Authentication Required.
|
||||
*/
|
||||
public static final int HTTP_PROXY_AUTH = 407;
|
||||
int HTTP_PROXY_AUTH = 407;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 408: Request Time-Out.
|
||||
*/
|
||||
public static final int HTTP_CLIENT_TIMEOUT = 408;
|
||||
int HTTP_CLIENT_TIMEOUT = 408;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 409: Conflict.
|
||||
*/
|
||||
public static final int HTTP_CONFLICT = 409;
|
||||
int HTTP_CONFLICT = 409;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 410: Gone.
|
||||
*/
|
||||
public static final int HTTP_GONE = 410;
|
||||
int HTTP_GONE = 410;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 411: Length Required.
|
||||
*/
|
||||
public static final int HTTP_LENGTH_REQUIRED = 411;
|
||||
int HTTP_LENGTH_REQUIRED = 411;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 412: Precondition Failed.
|
||||
*/
|
||||
public static final int HTTP_PRECON_FAILED = 412;
|
||||
int HTTP_PRECON_FAILED = 412;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 413: Request Entity Too Large.
|
||||
*/
|
||||
public static final int HTTP_ENTITY_TOO_LARGE = 413;
|
||||
int HTTP_ENTITY_TOO_LARGE = 413;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 414: Request-URI Too Large.
|
||||
*/
|
||||
public static final int HTTP_REQ_TOO_LONG = 414;
|
||||
int HTTP_REQ_TOO_LONG = 414;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 415: Unsupported Media Type.
|
||||
*/
|
||||
public static final int HTTP_UNSUPPORTED_TYPE = 415;
|
||||
int HTTP_UNSUPPORTED_TYPE = 415;
|
||||
|
||||
/* 5XX: server error */
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 500: Internal Server Error.
|
||||
*/
|
||||
public static final int HTTP_INTERNAL_ERROR = 500;
|
||||
int HTTP_INTERNAL_ERROR = 500;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 501: Not Implemented.
|
||||
*/
|
||||
public static final int HTTP_NOT_IMPLEMENTED = 501;
|
||||
int HTTP_NOT_IMPLEMENTED = 501;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 502: Bad Gateway.
|
||||
*/
|
||||
public static final int HTTP_BAD_GATEWAY = 502;
|
||||
int HTTP_BAD_GATEWAY = 502;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 503: Service Unavailable.
|
||||
*/
|
||||
public static final int HTTP_UNAVAILABLE = 503;
|
||||
int HTTP_UNAVAILABLE = 503;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 504: Gateway Timeout.
|
||||
*/
|
||||
public static final int HTTP_GATEWAY_TIMEOUT = 504;
|
||||
int HTTP_GATEWAY_TIMEOUT = 504;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 505: HTTP Version Not Supported.
|
||||
*/
|
||||
public static final int HTTP_VERSION = 505;
|
||||
int HTTP_VERSION = 505;
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ public enum SoapProtocol {
|
||||
*
|
||||
* @param value {@link SOAPConstants} 中的协议版本值
|
||||
*/
|
||||
private SoapProtocol(String value) {
|
||||
SoapProtocol(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user