Entry( final String url, final String method, final AmazonHttpHandler handler ) { this.asString = method + " " + url; this.handler = handler; this.matcher = URLMatcher.compile( url, true ); }
private boolean isHostAllowed( String originHost ) throws MalformedURLException { if ( config.alwaysAllowOrigin) return true; else for (URLMatcher matcher : config.allowedOriginMatchers) if ( matcher.matches( originHost, EMPTY_URL_PARAMS ) ) return true; return false; }
public String replace( final Map<String, String> foundParameters ) { val buffer = new StringBuilder(); replace( buffer, foundParameters ); return buffer.toString(); }
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 ); } } }
public static URLMatcher compile( final String string, final boolean doNotIgnoreSlashes ) { val compiler = new URLPatternCompiler( doNotIgnoreSlashes ); compiler.compile( string ); return new URLMatcher( compiler.patternMatchers ); }
public Entry( final String url, final HttpHandler handler ) { this.handler = handler; this.matcher = URLMatcher.compile( url, true ); this.url = url; }
boolean matchesIgnoredUrls( final String url ) { for ( final URLMatcher exceptionPattern : exceptionPatterns ) if ( exceptionPattern.matches( url, null ) ) return true; return false; }
private URI asHost(URLMatcher target ) throws URISyntaxException { val uri = new URI( target.replace( Collections.emptyMap() ) ); return new URI( uri.getScheme() + "://" + uri.getAuthority() + "/" ); } }
public static URLMatcher compile( final String string ) { return compile( string, false ); }
@Override public Boolean apply( final HttpServerExchange exchange, final Map<String, String> properties ) { val relativePath = exchange.getRelativePath(); return path.matches( relativePath, properties ); }
@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); } }
public static HttpHandler create( HttpHandler next, String url, Map<String, Object> headers ) { final Map<String, URLMatcher> convertedHeaders = new HashMap<>(); for ( Entry<String, Object> header : headers.entrySet() ){ final URLMatcher matcher = URLMatcher.compile( String.valueOf( header.getValue() ) ); convertedHeaders.put( header.getKey(), matcher ); } final URLMatcher urlMatcher = URLMatcher.compile( url ); return new StaticHeadersHttpHandler( next, urlMatcher, convertedHeaders ); } }
Map<String, String> extractRequestParameters( final WebSocketChannel channel ) { final String url = channel.getUrl(); final Map<String, String> foundParameters = new HashMap<>(); if ( !urlMatcher.matches( url, foundParameters ) ) throw new UnsupportedOperationException( "There was a huge mistake on implementation: it doesn't matched URL: " + url ); return foundParameters; }
@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(); }
public static RequestMatcher from(final String path ) { return new VirtualHostMatcher( URLMatcher.compile( path ) ); } }
public boolean matches( final String url ) { return matcher.matches( url, null ) && !matchesIgnoredUrls( url ); }
@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); }
private List<URLMatcher> convertToURLMatcher( final List<String> urls ) { final List<URLMatcher> matchers = new TinyList<>(); for ( final String url : urls ) matchers.add( URLMatcher.compile( url ) ); return matchers; } }
public boolean matches( final String string, final Map<String, String> foundParameters ) { return matches( new StringCursor( string ), foundParameters ); }
public static RequestMatcher from(final String path ) { return new PathMatcher( URLMatcher.compile( path ) ); } }