add UrlBuilder getPortWithDefault

This commit is contained in:
bwcx_jzy 2022-10-13 15:23:33 +08:00
parent dca6cbe4b1
commit 311829660f
No known key found for this signature in database
GPG Key ID: 5E48E9372088B9E5

View File

@ -291,6 +291,26 @@ public final class UrlBuilder implements Builder<String> {
return port; return port;
} }
/**
* 获取端口如果未自定义返回协议默认端口
*
* @return 端口
*/
public int getPortWithDefault() {
int port = getPort();
if (port != -1) {
return port;
}
switch (this.scheme) {
case "http":
return 80;
case "https":
return 443;
default:
return port;
}
}
/** /**
* 设置端口默认-1 * 设置端口默认-1
* *