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; }
boolean matchesIgnoredUrls( final String url ) { for ( final URLMatcher exceptionPattern : exceptionPatterns ) if ( exceptionPattern.matches( url, null ) ) return true; return false; }
@Override public Boolean apply( final HttpServerExchange exchange, final Map<String, String> properties ) { val relativePath = exchange.getRelativePath(); return path.matches( relativePath, properties ); }
public boolean matches( final String url ) { return matcher.matches( url, null ) && !matchesIgnoredUrls( url ); }
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; }
public boolean matches( final String string, final Map<String, String> foundParameters ) { return matches( new StringCursor( string ), foundParameters ); }
AmazonHttpHandler retrieveHttpHandler( AmazonLambdaRequest request ) { final String path = request.getPath().replaceFirst( "/$", "" ); log.debug( "Retrieving HTTP Handler for request: " + request.httpMethod + " " + path ); final List<Entry> list = entriesMatcher.getOrDefault( request.getHttpMethod(), Collections.emptyList() ); for ( final Entry entry : list ) if ( entry.getMatcher().matches( path, request.pathParameters ) ) return entry.getHandler(); return null; }
@Override public Boolean apply( final HttpServerExchange exchange, final Map<String, String> properties ) { val hostHeader = exchange.getRequestHeaders().getFirst( Headers.HOST ); if ( hostHeader == null ) { log.warn( "No HOST header found." ); return true; } val host = stripHostFromHeader( hostHeader ); return virtualHost.matches( host, properties ); }
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 ); } } }
MatchedEntry retrieveEntryThatMatchesUrlFromList( final List<Entry> list, final String url ) { final Map<String, String> matchedPathParameters = new HashMap<>(); for ( final Entry entry : list ) if ( entry.getMatcher().matches( url, matchedPathParameters ) ) return new MatchedEntry( url, entry.getHandler(), matchedPathParameters ); return null; }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { exchange.putAttachment( WebJarNotFound.RELATIVE_PATH, exchange.getRelativePath() ); final LastValueOnlyMap<String,String> matcher = new LastValueOnlyMap<>(); if ( uri.matches( exchange.getRelativePath(), matcher ) ) { exchange.setRelativePath(matcher.getValue()); handler.handleRequest(exchange); } else { fallbackHandler.handleRequest( exchange ); } } }