Fix armeria latestDepTest (#8247)
This commit is contained in:
parent
1b6d25e519
commit
69ee671e99
|
@ -24,7 +24,18 @@ enum ArmeriaHttpClientAttributesGetter
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUrl(RequestContext ctx) {
|
public String getUrl(RequestContext ctx) {
|
||||||
return request(ctx).uri().toString();
|
HttpRequest request = request(ctx);
|
||||||
|
StringBuilder uri = new StringBuilder();
|
||||||
|
String scheme = request.scheme();
|
||||||
|
if (scheme != null) {
|
||||||
|
uri.append(scheme).append("://");
|
||||||
|
}
|
||||||
|
String authority = request.authority();
|
||||||
|
if (authority != null) {
|
||||||
|
uri.append(authority);
|
||||||
|
}
|
||||||
|
uri.append(request.path());
|
||||||
|
return uri.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -41,12 +41,32 @@ public final class ArmeriaNetClientAttributesGetter
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getPeerName(RequestContext ctx) {
|
public String getPeerName(RequestContext ctx) {
|
||||||
return request(ctx).uri().getHost();
|
HttpRequest request = request(ctx);
|
||||||
|
String authority = request.authority();
|
||||||
|
if (authority == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int separatorPos = authority.indexOf(':');
|
||||||
|
return separatorPos == -1 ? authority : authority.substring(0, separatorPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Integer getPeerPort(RequestContext ctx) {
|
public Integer getPeerPort(RequestContext ctx) {
|
||||||
return request(ctx).uri().getPort();
|
HttpRequest request = request(ctx);
|
||||||
|
String authority = request.authority();
|
||||||
|
if (authority == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int separatorPos = authority.indexOf(':');
|
||||||
|
if (separatorPos == -1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(authority.substring(separatorPos + 1));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -57,11 +57,21 @@ public abstract class AbstractArmeriaHttpClientTest extends AbstractHttpClientTe
|
||||||
@Override
|
@Override
|
||||||
public HttpRequest buildRequest(String method, URI uri, Map<String, String> headers) {
|
public HttpRequest buildRequest(String method, URI uri, Map<String, String> headers) {
|
||||||
return HttpRequest.of(
|
return HttpRequest.of(
|
||||||
RequestHeaders.builder(HttpMethod.valueOf(method), uri.toString())
|
RequestHeaders.builder()
|
||||||
|
.method(HttpMethod.valueOf(method))
|
||||||
|
.scheme(uri.getScheme())
|
||||||
|
.authority(uri.getAuthority())
|
||||||
|
.path(pathAndQuery(uri))
|
||||||
.set(headers.entrySet())
|
.set(headers.entrySet())
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String pathAndQuery(URI uri) {
|
||||||
|
String path = uri.getPath();
|
||||||
|
String query = uri.getQuery();
|
||||||
|
return (path == null ? "" : path) + (query == null ? "" : "?" + query);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int sendRequest(HttpRequest request, String method, URI uri, Map<String, String> headers) {
|
public int sendRequest(HttpRequest request, String method, URI uri, Map<String, String> headers) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue