@Override public String authority() { return delegate.authority(); }
/** * Returns the authority of this request. This method is a shortcut of {@code headers().authority()}. */ default String authority() { return headers().authority(); }
/** * Returns the {@link HttpHeaderNames#AUTHORITY AUTHORITY} of this message, in the form of * {@code "hostname:port"}. * * @return the authority, or {@code null} if there's no such header */ @Nullable default String authority() { return headers().authority(); }
/** * Returns the authority of the {@link Request}. * * @return the authority. {@code "?"} if the {@link Request} has failed even before its headers are * properly constructed. * * @throws RequestLogAvailabilityException if this property is not available yet */ default String authority() { final String authority = requestHeaders().authority(); assert authority != null; return authority; }
/** * Returns a remote host from the specified {@link HttpHeaders} and {@link Channel}. */ public static String remoteHost(HttpHeaders headers, Channel channel) { requireNonNull(headers, "headers"); requireNonNull(channel, "channel"); String host = headers.authority(); if (host == null) { host = ((InetSocketAddress) channel.remoteAddress()).getHostString(); } else { final int colonIdx = host.lastIndexOf(':'); if (colonIdx > 0) { host = host.substring(0, colonIdx); } } return host; }
/** * Sets the authority of this request. This method is a shortcut of {@code headers().authority(...)}. * * @return {@code this} */ default HttpRequest authority(String authority) { headers().authority(authority); return this; }
@VisibleForTesting static void setHttp2Authority(@Nullable String authority, HttpHeaders out) { // The authority MUST NOT include the deprecated "userinfo" subcomponent if (authority != null) { final String actualAuthority; if (authority.isEmpty()) { actualAuthority = ""; } else { final int start = authority.indexOf('@') + 1; if (start == 0) { actualAuthority = authority; } else if (authority.length() == start) { throw new IllegalArgumentException("authority: " + authority); } else { actualAuthority = authority.substring(start); } } out.authority(actualAuthority); } }
private String hostname(ChannelHandlerContext ctx, HttpHeaders headers) { final String hostname = headers.authority(); if (hostname == null) { // Fill the authority with the default host name and current port, just in case the client did not // send it. final String defaultHostname = config.defaultVirtualHost().defaultHostname(); final int port = ((InetSocketAddress) ctx.channel().localAddress()).getPort(); headers.authority(defaultHostname + ':' + port); return defaultHostname; } final int hostnameColonIdx = hostname.lastIndexOf(':'); if (hostnameColonIdx < 0) { return hostname; } return hostname.substring(0, hostnameColonIdx); }
@Nullable private static String getAuthority(RequestContext ctx, HttpHeaders headers) { String authority = headers.authority(); if (authority != null) { final Pattern portPattern = ctx.sessionProtocol().isTls() ? PORT_443 : PORT_80; final Matcher m = portPattern.matcher(authority); if (m.find()) { authority = authority.substring(0, m.start()); } return authority; } return null; }
@Override protected HttpResponse doExecute(ClientRequestContext ctx, HttpRequest req) throws Exception { final boolean hasInitialAuthority = !isNullOrEmpty(req.headers().authority()); final CompletableFuture<HttpResponse> responseFuture = new CompletableFuture<>(); final HttpResponse res = HttpResponse.from(responseFuture); final HttpRequestDuplicator reqDuplicator = new HttpRequestDuplicator(req, 0, ctx.eventLoop()); doExecute0(ctx, reqDuplicator, req, res, responseFuture, hasInitialAuthority); return res; }
remoteServiceName = this.remoteServiceName; } else { final String authority = log.requestHeaders().authority(); if (!"?".equals(authority)) { remoteServiceName = authority;
@VisibleForTesting static String extractHost(ClientRequestContext ctx, HttpRequest req, Endpoint endpoint) { String host = extractHost(ctx.additionalRequestHeaders().authority()); if (host != null) { return host; } host = extractHost(req.authority()); if (host != null) { return host; } return endpoint.host(); }
/** * Creates a new builder with the specified {@link HttpRequest}. * * @param server whether this builder will build a server-side context. * @param request the {@link HttpRequest}. */ protected AbstractRequestContextBuilder(boolean server, HttpRequest request) { this.server = server; this.request = requireNonNull(request, "request"); sessionProtocol = SessionProtocol.H2C; final HttpMethod method = request.headers().method(); checkArgument(method != null, "request.method is not valid: %s", request); this.method = method; authority = firstNonNull(request.headers().authority(), FALLBACK_AUTHORITY); final String pathAndQueryStr = request.headers().path(); final PathAndQuery pathAndQuery = PathAndQuery.parse(pathAndQueryStr); checkArgument(pathAndQuery != null, "request.path is not valid: %s", request); path = pathAndQuery.path(); query = pathAndQuery.query(); }
private static MetaData.Request toRequestMetadata(ServiceRequestContext ctx, AggregatedHttpMessage aReq) { // Construct the HttpURI final StringBuilder uriBuf = new StringBuilder(); final HttpHeaders aHeaders = aReq.headers(); uriBuf.append(ctx.sessionProtocol().isTls() ? "https" : "http"); uriBuf.append("://"); uriBuf.append(aHeaders.authority()); uriBuf.append(aHeaders.path()); final HttpURI uri = new HttpURI(uriBuf.toString()); uri.setPath(ctx.mappedPath()); // Convert HttpHeaders to HttpFields final HttpFields jHeaders = new HttpFields(aHeaders.size()); aHeaders.forEach(e -> { final AsciiString key = e.getKey(); if (!key.isEmpty() && key.byteAt(0) != ':') { jHeaders.add(key.toString(), e.getValue()); } }); return new MetaData.Request( aHeaders.method().name(), uri, HttpVersion.HTTP_1_1, jHeaders, aReq.content().length()); }
final String host = log.requestHeaders().authority(); assert host != null; span.tag("http.host", host);
private static ServiceRequestContext newServiceContext( String path, @Nullable String query) throws Exception { final InetSocketAddress remoteAddress = new InetSocketAddress( InetAddress.getByAddress("client.com", new byte[] { 1, 2, 3, 4 }), 5678); final InetSocketAddress localAddress = new InetSocketAddress( InetAddress.getByAddress("server.com", new byte[] { 5, 6, 7, 8 }), 8080); final String pathAndQuery = path + (query != null ? '?' + query : ""); final HttpRequest req = HttpRequest.of(HttpHeaders.of(HttpMethod.GET, pathAndQuery) .authority("server.com:8080") .set(HttpHeaderNames.USER_AGENT, "some-client")); final ServiceRequestContext ctx = ServiceRequestContextBuilder.of(req) .sslSession(newSslSession()) .remoteAddress(remoteAddress) .localAddress(localAddress) .clientAddress(InetAddress.getByName("9.10.11.12")) .build(); ctx.attr(MY_ATTR).set(new CustomValue("some-attr")); return ctx; }
private static ClientRequestContext newClientContext( String path, @Nullable String query) throws Exception { final InetSocketAddress remoteAddress = new InetSocketAddress( InetAddress.getByAddress("server.com", new byte[] { 1, 2, 3, 4 }), 8080); final InetSocketAddress localAddress = new InetSocketAddress( InetAddress.getByAddress("client.com", new byte[] { 5, 6, 7, 8 }), 5678); final String pathAndQuery = path + (query != null ? '?' + query : ""); final HttpRequest req = HttpRequest.of(HttpHeaders.of(HttpMethod.GET, pathAndQuery) .authority("server.com:8080") .set(HttpHeaderNames.USER_AGENT, "some-client")); final ClientRequestContext ctx = ClientRequestContextBuilder.of(req) .remoteAddress(remoteAddress) .localAddress(localAddress) .endpoint(Endpoint.of("server.com", 8080)) .sslSession(newSslSession()) .build(); ctx.attr(MY_ATTR).set(new CustomValue("some-attr")); return ctx; }
.authority("foo.com")); final RpcRequest rpcReq = RpcRequest.of(HelloService.Iface.class, "hello", "Armeria"); final HttpResponse res = HttpResponse.of(HttpStatus.OK);
.authority("foo.com")); final ServiceRequestContext ctx = ServiceRequestContextBuilder.of(req) .service(stub)