public String replace( final Map<String, String> foundParameters ) { val buffer = new StringBuilder(); replace( buffer, foundParameters ); return buffer.toString(); }
private URI asHost(URLMatcher target ) throws URISyntaxException { val uri = new URI( target.replace( Collections.emptyMap() ) ); return new URI( uri.getScheme() + "://" + uri.getAuthority() + "/" ); } }
@Override public ProxyTarget findTarget(HttpServerExchange exchange) { try { val values = new HashMap<String, String>(); if ( requestMatcher.apply( exchange, values ) ) { val uri = new URI( matcher.replace( values ) ); fixURL( exchange, uri ); return super.findTarget(exchange); } return null; } catch (URISyntaxException e) { throw new RuntimeException(e); } }
@Override public void doFilter(HttpServerExchange exchange, FilterChain chain) throws Exception { final Map<String, String> properties = new HashMap<>(); if ( requestMatcher.apply( exchange, properties ) ) { final String replaced = targetPath.replace(properties); Redirect.to( exchange, replaced ); } else chain.runNext(); }
private void sendHeaders( HttpServerExchange exchange ){ final String relativePath = exchange.getRelativePath(); final Map<String, String> variables = new HashMap<>(); if ( matcher.matches( relativePath, variables ) ) { for ( final Entry<String, URLMatcher> entry : headers.entrySet() ) { final HttpString header = new HttpString( entry.getKey() ); final String value = entry.getValue().replace( variables ); exchange.getResponseHeaders().add( header, value ); } } }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { final Map<String, String> properties = new HashMap<>(); if ( requestMatcher.apply( exchange, properties ) ) exchange.setRelativePath(targetPath.replace(properties)); next.handleRequest(exchange); }