mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix check bug
This commit is contained in:
@@ -9,9 +9,19 @@ public enum Header {
|
||||
|
||||
//------------------------------------------------------------- 通用头域
|
||||
/**
|
||||
* 提供验证头
|
||||
* 提供验证头,例如:
|
||||
* <pre>
|
||||
* Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l
|
||||
* </pre>
|
||||
*/
|
||||
AUTHORIZATION("Authorization"),
|
||||
/**
|
||||
* 提供给代理服务器的用于身份验证的凭证,例如:
|
||||
* <pre>
|
||||
* Proxy-Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l
|
||||
* </pre>
|
||||
*/
|
||||
PROXY_AUTHORIZATION("Proxy-Authorization"),
|
||||
/**
|
||||
* 提供日期和时间标志,说明报文是什么时间创建的
|
||||
*/
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
@@ -981,16 +980,32 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 简单验证
|
||||
* 简单验证,生成的头信息类似于:
|
||||
* <pre>
|
||||
* Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l
|
||||
* </pre>
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param password 密码
|
||||
* @return HttpRequest
|
||||
* @return this
|
||||
*/
|
||||
public HttpRequest basicAuth(String username, String password) {
|
||||
final String data = username.concat(":").concat(password);
|
||||
final String base64 = Base64.encode(data, charset);
|
||||
return auth("Basic " + base64);
|
||||
return auth(HttpUtil.buildBasicAuth(username, password, charset));
|
||||
}
|
||||
|
||||
/**
|
||||
* 简单代理验证,生成的头信息类似于:
|
||||
* <pre>
|
||||
* Proxy-Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l
|
||||
* </pre>
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param password 密码
|
||||
* @return this
|
||||
* @since 5.4.6
|
||||
*/
|
||||
public HttpRequest basicProxyAuth(String username, String password) {
|
||||
return proxyAuth(HttpUtil.buildBasicAuth(username, password, charset));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1005,6 +1020,18 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证,简单插入Authorization头
|
||||
*
|
||||
* @param content 验证内容
|
||||
* @return HttpRequest
|
||||
* @since 5.4.6
|
||||
*/
|
||||
public HttpRequest proxyAuth(String content) {
|
||||
header(Header.PROXY_AUTHORIZATION, content, true);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = StrUtil.builder();
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.io.FastByteArrayOutputStream;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
@@ -870,4 +871,21 @@ public class HttpUtil {
|
||||
public static SimpleServer createServer(int port) {
|
||||
return new SimpleServer(port);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建简单的账号秘密验证信息,构建后类似于:
|
||||
* <pre>
|
||||
* Basic YWxhZGRpbjpvcGVuc2VzYW1l
|
||||
* </pre>
|
||||
*
|
||||
* @param username 账号
|
||||
* @param password 密码
|
||||
* @param charset 编码(如果账号或密码中有非ASCII字符适用)
|
||||
* @return 密码验证信息
|
||||
* @since 5.4.6
|
||||
*/
|
||||
public static String buildBasicAuth(String username, String password, Charset charset){
|
||||
final String data = username.concat(":").concat(password);
|
||||
return "Basic " + Base64.encode(data, charset);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user