private URI getBaseUri(final Request request) { try { return new URI(request.getScheme(), null, request.getServerName(), request.getServerPort(), getBasePath(request), null, null); } catch (final URISyntaxException ex) { throw new IllegalArgumentException(ex); } }
public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { String param; httpResponse.setContentType(TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); Enumeration<?> e = httpRequest.getHeaderNames(); while (e.hasMoreElements()) { param = e.nextElement().toString(); if (param.startsWith("X-redirect") && !redirectDone.getAndSet(true)) { httpResponse.addHeader("Location", httpRequest.getHeader(param)); httpResponse.setStatus(302); httpResponse.getOutputStream().flush(); httpResponse.getOutputStream().close(); return; } } if (r.getScheme().equalsIgnoreCase("https")) { httpResponse.addHeader("X-httpToHttps", "PASS"); redirectDone.getAndSet(false); } httpResponse.setStatus(200); httpResponse.getOutputStream().flush(); httpResponse.getOutputStream().close(); } }
public boolean isConfidential(Request request) { return _forwarded && request.getScheme().equalsIgnoreCase(HttpSchemes.HTTPS); }
public boolean isConfidential(Request request) { return _forwarded && request.getScheme().equalsIgnoreCase(HttpSchemes.HTTPS); }
public boolean isConfidential(Request request) { return _forwarded && request.getScheme().equalsIgnoreCase(HttpSchemes.HTTPS); }
public boolean isConfidential(Request request) { return _forwarded && request.getScheme().equalsIgnoreCase(HttpSchemes.HTTPS); }
public boolean isConfidential(Request request) { return _forwarded && request.getScheme().equalsIgnoreCase(HttpSchemes.HTTPS); }
@Override public StringBuffer getRequestURL() { final StringBuffer url = new StringBuffer(48); String scheme = getScheme(); int port = getServerPort(); url.append(scheme); url.append("://"); url.append(getServerName()); if (_port > 0 && ((scheme.equalsIgnoreCase(URIUtil.HTTP) && port != 80) || (scheme.equalsIgnoreCase(URIUtil.HTTPS) && port != 443))) { url.append(':'); url.append(_port); } url.append(getRequestURI()); return url; }
@Override public StringBuffer getRequestURL() { final StringBuffer url = new StringBuffer(48); String scheme = getScheme(); int port = getServerPort(); url.append(scheme); url.append("://"); url.append(getServerName()); if (_port > 0 && ((scheme.equalsIgnoreCase(URIUtil.HTTP) && port != 80) || (scheme.equalsIgnoreCase(URIUtil.HTTPS) && port != 443))) { url.append(':'); url.append(_port); } url.append(getRequestURI()); return url; }
@Override public StringBuffer getRequestURL() { final StringBuffer url = new StringBuffer(128); URIUtil.appendSchemeHostPort(url,getScheme(),getServerName(),getServerPort()); url.append(getRequestURI()); return url; }
@Override public StringBuffer getRequestURL() { final StringBuffer url = new StringBuffer(128); URIUtil.appendSchemeHostPort(url,getScheme(),getServerName(),getServerPort()); url.append(getRequestURI()); return url; }
@Override public StringBuffer getRequestURL() { final StringBuffer url = new StringBuffer(128); URIUtil.appendSchemeHostPort(url,getScheme(),getServerName(),getServerPort()); url.append(getRequestURI()); return url; }
/** * Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and, but it does not include a * path. * <p> * Because this method returns a <code>StringBuffer</code>, not a string, you can modify the URL easily, for example, to append path and query parameters. * * This method is useful for creating redirect messages and for reporting errors. * * @return "scheme://host:port" */ public StringBuilder getRootURL() { StringBuilder url = new StringBuilder(128); URIUtil.appendSchemeHostPort(url,getScheme(),getServerName(),getServerPort()); return url; }
/** * Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and, but it does not include a * path. * <p> * Because this method returns a <code>StringBuffer</code>, not a string, you can modify the URL easily, for example, to append path and query parameters. * * This method is useful for creating redirect messages and for reporting errors. * * @return "scheme://host:port" */ public StringBuilder getRootURL() { StringBuilder url = new StringBuilder(128); URIUtil.appendSchemeHostPort(url,getScheme(),getServerName(),getServerPort()); return url; }
/** * Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and, but it does not include a * path. * <p> * Because this method returns a <code>StringBuffer</code>, not a string, you can modify the URL easily, for example, to append path and query parameters. * * This method is useful for creating redirect messages and for reporting errors. * * @return "scheme://host:port" */ public StringBuilder getRootURL() { StringBuilder url = new StringBuilder(128); URIUtil.appendSchemeHostPort(url,getScheme(),getServerName(),getServerPort()); return url; }
@Override public int getServerPort() { HttpURI uri = _metadata.getURI(); int port = (uri.getHost()==null)?findServerPort():uri.getPort(); // If no port specified, return the default port for the scheme if (port <= 0) { if (getScheme().equalsIgnoreCase(URIUtil.HTTPS)) return 443; return 80; } // return a specific port return port; }
@Override public int getServerPort() { MetaData.Request metadata = _metaData; HttpURI uri = metadata==null?null:metadata.getURI(); int port = (uri==null||uri.getHost()==null)?findServerPort():uri.getPort(); // If no port specified, return the default port for the scheme if (port <= 0) { if (getScheme().equalsIgnoreCase(URIUtil.HTTPS)) return 443; return 80; } // return a specific port return port; }
@Test public void testNoXForwardedProto() throws Exception { final Request request = mock(Request.class); final Response response = mock(Response.class); final String protocol = "protocol"; when(request.getScheme()).thenReturn("protocol"); InMemoryEventClient eventClient = new InMemoryEventClient(); DelimitedRequestLog logger = new DelimitedRequestLog(file.getAbsolutePath(), 1, Long.MAX_VALUE, null, eventClient); logger.log(request, response); logger.stop(); List<Object> events = eventClient.getEvents(); Assert.assertEquals(events.size(), 1); HttpRequestEvent event = (HttpRequestEvent) events.get(0); Assert.assertEquals(event.getProtocol(), protocol); }
@Test public void testNoXForwardedProto() throws Exception { Request request = mock(Request.class); Response response = mock(Response.class); String protocol = "protocol"; when(request.getScheme()).thenReturn("protocol"); when(request.getHttpVersion()).thenReturn(HTTP_2); InMemoryEventClient eventClient = new InMemoryEventClient(); DelimitedRequestLog logger = new DelimitedRequestLog(file.getAbsolutePath(), 1, 256, Long.MAX_VALUE, null, eventClient, false); logger.log(request, response, 0, 0, 0, new DoubleSummaryStats(new DoubleSummaryStatistics())); logger.stop(); List<Object> events = eventClient.getEvents(); assertEquals(events.size(), 1); HttpRequestEvent event = (HttpRequestEvent) events.get(0); assertEquals(event.getProtocol(), protocol); }
@Override public void customize(Connector connector, HttpConfiguration channelConfig, Request request) { if (request.getHttpChannel().getEndPoint() instanceof DecryptedEndPoint) { if (request.getHttpURI().getScheme()==null) request.setScheme(HttpScheme.HTTPS.asString()); SslConnection.DecryptedEndPoint ssl_endp = (DecryptedEndPoint)request.getHttpChannel().getEndPoint(); SslConnection sslConnection = ssl_endp.getSslConnection(); SSLEngine sslEngine=sslConnection.getSSLEngine(); customize(sslEngine,request); } if (HttpScheme.HTTPS.is(request.getScheme())) customizeSecure(request); }