Fix armeria latestDepTest (#8247)
This commit is contained in:
parent
1b6d25e519
commit
69ee671e99
|
@ -24,7 +24,18 @@ enum ArmeriaHttpClientAttributesGetter
|
|||
|
||||
@Override
|
||||
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
|
||||
|
|
|
@ -41,12 +41,32 @@ public final class ArmeriaNetClientAttributesGetter
|
|||
@Nullable
|
||||
@Override
|
||||
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
|
||||
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
|
||||
|
|
|
@ -57,11 +57,21 @@ public abstract class AbstractArmeriaHttpClientTest extends AbstractHttpClientTe
|
|||
@Override
|
||||
public HttpRequest buildRequest(String method, URI uri, Map<String, String> headers) {
|
||||
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())
|
||||
.build());
|
||||
}
|
||||
|
||||
private static String pathAndQuery(URI uri) {
|
||||
String path = uri.getPath();
|
||||
String query = uri.getQuery();
|
||||
return (path == null ? "" : path) + (query == null ? "" : "?" + query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int sendRequest(HttpRequest request, String method, URI uri, Map<String, String> headers) {
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue