mirror of
https://gitee.com/dromara/hutool.git
synced 2026-02-09 09:16:26 +08:00
Merge pull request #4216 from zouzanyan/v5-dev-zouzanyan
HttpUtil类 bug修复
This commit is contained in:
@@ -5,6 +5,7 @@ import cn.hutool.core.convert.Convert;
|
|||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.io.StreamProgress;
|
import cn.hutool.core.io.StreamProgress;
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.net.RFC3986;
|
import cn.hutool.core.net.RFC3986;
|
||||||
import cn.hutool.core.net.url.UrlQuery;
|
import cn.hutool.core.net.url.UrlQuery;
|
||||||
@@ -580,9 +581,11 @@ public class HttpUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 以&结尾则去除之
|
// 以&结尾则去除之
|
||||||
int lastIndex = builder.length() - 1;
|
if (!builder.isEmpty()) {
|
||||||
if ('&' == builder.charAt(lastIndex)) {
|
int lastIndex = builder.length() - 1;
|
||||||
builder.delTo(lastIndex);
|
if ('&' == builder.charAt(lastIndex)) {
|
||||||
|
builder.delTo(lastIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
@@ -883,6 +886,8 @@ public class HttpUtil {
|
|||||||
* @since 5.4.6
|
* @since 5.4.6
|
||||||
*/
|
*/
|
||||||
public static String buildBasicAuth(String username, String password, Charset charset) {
|
public static String buildBasicAuth(String username, String password, Charset charset) {
|
||||||
|
Assert.notNull(username, "username must not be null");
|
||||||
|
Assert.notNull(password, "password must not be null");
|
||||||
final String data = username.concat(":").concat(password);
|
final String data = username.concat(":").concat(password);
|
||||||
return "Basic " + Base64.encode(data, charset);
|
return "Basic " + Base64.encode(data, charset);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -327,6 +327,12 @@ public class HttpUtilTest {
|
|||||||
assertEquals("", encodeResult);
|
assertEquals("", encodeResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void normalizEampersandParamsTest() {
|
||||||
|
final String encodeResult = HttpUtil.normalizeParams("&", CharsetUtil.CHARSET_UTF_8);
|
||||||
|
assertEquals("", encodeResult);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getMimeTypeTest() {
|
public void getMimeTypeTest() {
|
||||||
final String mimeType = HttpUtil.getMimeType("aaa.aaa");
|
final String mimeType = HttpUtil.getMimeType("aaa.aaa");
|
||||||
|
|||||||
Reference in New Issue
Block a user