@Override public String getRequestScheme() { return exchange.getRequestScheme(); }
@Override public String readAttribute(final HttpServerExchange exchange) { return exchange.getRequestScheme(); }
/** * Use the HttpServerExchange supplied to check if this request is already 'sufficiently' confidential. * * Here we say 'sufficiently' as sub-classes can override this and maybe even go so far as querying the actual SSLSession. * * @param exchange - The {@link HttpServerExchange} for the request being processed. * @return true if the request is 'sufficiently' confidential, false otherwise. */ protected boolean isConfidential(final HttpServerExchange exchange) { return exchange.getRequestScheme().equals("https"); }
@Override public boolean resolve(HttpServerExchange value) { return value.getRequestScheme().equals("https"); }
@Override public boolean secure() { return exchange.getRequestScheme().equalsIgnoreCase("https"); }
public boolean isSecure() { Boolean secure = getAttachment(SECURE_REQUEST); if(secure != null && secure) { return true; } String scheme = getRequestScheme(); if (scheme != null && scheme.equalsIgnoreCase(HTTPS)) { return true; } return false; }
/** * Return the port that this request was sent to. In general this will be the value of the Host * header, minus the host name. * * @return The port part of the destination address */ public int getHostPort() { String host = requestHeaders.getFirst(Headers.HOST); if (host != null) { //for ipv6 addresses we make sure we take out the first part, which can have multiple occurrences of : final int colonIndex; if (host.startsWith("[")) { colonIndex = host.indexOf(':', host.indexOf(']')); } else { colonIndex = host.indexOf(':'); } if (colonIndex != -1) { try { return Integer.parseInt(host.substring(colonIndex + 1)); } catch (NumberFormatException ignore) {} } if (getRequestScheme().equals("https")) { return 443; } else if (getRequestScheme().equals("http")) { return 80; } } return getDestinationAddress().getPort(); }
/** * Return the host, and also the port if this request was sent to a non-standard port. In general * this will just be the value of the Host header. * <p> * If this resolves to an IPv6 address it *will* be enclosed by square brackets. The return * value of this method is suitable for inclusion in a URL. * * @return The host and port part of the destination address */ public String getHostAndPort() { String host = requestHeaders.getFirst(Headers.HOST); if (host == null) { InetSocketAddress address = getDestinationAddress(); host = NetworkUtils.formatPossibleIpv6Address(address.getHostString()); int port = address.getPort(); if (!((getRequestScheme().equals("http") && port == 80) || (getRequestScheme().equals("https") && port == 443))) { host = host + ":" + port; } } return host; }
/** * Determine the default origin, to allow for local access. * @param exchange the current HttpExchange. * @return the default origin (aka current server). */ public static String defaultOrigin(HttpServerExchange exchange) { String host = NetworkUtils.formatPossibleIpv6Address(exchange.getHostName()); String protocol = exchange.getRequestScheme(); int port = exchange.getHostPort(); //This browser set header should not need IPv6 escaping StringBuilder allowedOrigin = new StringBuilder(256); allowedOrigin.append(protocol).append("://").append(host); if (!isDefaultPort(port, protocol)) { allowedOrigin.append(':').append(port); } return allowedOrigin.toString(); }
static void sendRedirect(final HttpServerExchange exchange, final String location) { // TODO - String concatenation to construct URLS is extremely error prone - switch to a URI which will better handle this. String loc = exchange.getRequestScheme() + "://" + exchange.getHostAndPort() + location; exchange.getResponseHeaders().put(Headers.LOCATION, loc); } }
StringBuilder uri = new StringBuilder(exchange.getRequestScheme()); uri.append("://"); uri.append(exchange.getHostAndPort());
/** * Reconstructs the complete URL as seen by the user. This includes scheme, host name etc, * but does not include query string. * <p> * This is not decoded. */ public String getRequestURL() { if (isHostIncludedInRequestURI()) { return getRequestURI(); } else { return getRequestScheme() + "://" + getHostAndPort() + getRequestURI(); } }
sb.append(" remoteHost=" + exchange.getSourceAddress().getHostName() + "\n"); sb.append(" scheme=" + exchange.getRequestScheme() + "\n"); sb.append(" host=" + exchange.getRequestHeaders().getFirst(Headers.HOST) + "\n"); sb.append(" serverPort=" + exchange.getDestinationAddress().getPort() + "\n");
port = Integer.parseInt(mostRecent(forwardedPort)); if(port > 0) { String scheme = exchange.getRequestScheme();
requestHeaders.put(Http2ReceiveListener.PATH, path.toString()); requestHeaders.put(Http2ReceiveListener.AUTHORITY, exchange.getHostAndPort()); requestHeaders.put(Http2ReceiveListener.SCHEME, exchange.getRequestScheme()); exchange.setRequestMethod(method); exchange.setProtocol(Protocols.HTTP_1_1); exchange.setRequestScheme(this.exchange.getRequestScheme()); try { Connectors.setExchangeRequestPath(exchange, path, getUndertowOptions().get(UndertowOptions.URL_CHARSET, StandardCharsets.UTF_8.name()), getUndertowOptions().get(UndertowOptions.DECODE_URL, true), getUndertowOptions().get(UndertowOptions.ALLOW_ENCODED_SLASH, false), new StringBuilder(), getUndertowOptions().get(UndertowOptions.MAX_PARAMETERS, UndertowOptions.DEFAULT_MAX_HEADERS));
request.putAttachment(ProxiedRequestAttachments.IS_SSL, proto.equals("https")); } else { final String proto = exchange.getRequestScheme().equals("https") ? "https" : "http"; request.getRequestHeaders().put(Headers.X_FORWARDED_PROTO, proto); request.putAttachment(ProxiedRequestAttachments.IS_SSL, proto.equals("https"));
exchange.setRequestScheme(initial.getRequestScheme()); exchange.setRequestMethod(initial.getRequestMethod()); exchange.setQueryString(initial.getQueryString());
/** * Use the HttpServerExchange supplied to check if this request is already 'sufficiently' confidential. * * Here we say 'sufficiently' as sub-classes can override this and maybe even go so far as querying the actual SSLSession. * * @param exchange - The {@link HttpServerExchange} for the request being processed. * @return true if the request is 'sufficiently' confidential, false otherwise. */ protected boolean isConfidential(final HttpServerExchange exchange) { return exchange.getRequestScheme().equals("https"); }
@Override public boolean isSecure() { String protocol = exchange.getRequestScheme(); return protocol.equalsIgnoreCase("https"); }
public boolean isSecure() { Boolean secure = getAttachment(SECURE_REQUEST); if(secure != null && secure) { return true; } String scheme = getRequestScheme(); if (scheme != null && scheme.equalsIgnoreCase(HTTPS)) { return true; } return false; }