String stripHostFromHeader( final String hostHeader ) { val cursor = new StringCursor( hostHeader ); if ( !cursor.shiftCursorToNextChar( ':' ) ) cursor.end(); else cursor.prev(); val host = cursor.substringUntilCursor(); return host; }
private String getAuthString( StringCursor headerValue ) { headerValue.cursorAt( PREFIX_LENGTH ); headerValue.mark(); headerValue.end(); return headerValue.substringFromLastMark(); }
/** * Shift the cursor to the next occurrence of {@code ch} and returns * {@code true}. Otherwise, it will keep the cursor at same position, but * will return {@code false}. * * @param ch * @return */ public boolean shiftCursorToNextChar( final char ch ) { mark(); while ( hasNext() ) if ( next() == ch ) return true; flip(); return false; }
@Override public boolean matches( final StringCursor string , final Map<String, String> foundParameters ) { val pattern = new StringCursor( patternChars ); final char firstPatternChar = pattern.next(); return string.shiftCursorToNextChar( firstPatternChar ) && pattern.matches( string ); }
@Override public boolean matches( final StringCursor string , final Map<String, String> foundParameters ) { val pattern = new StringCursor( patternChars ); return pattern.matches( string ); }
private UsernameAndPasswordCredential convertToCredential( StringCursor decodedCredentials ) { decodedCredentials.shiftCursorToNextChar( COLON ); final String username = decodedCredentials.substringFromLastMark(1); decodedCredentials.mark(); decodedCredentials.end(); final String password = decodedCredentials.substringFromLastMark(); return new UsernameAndPasswordCredential( username, password ); }
private void appendPlaceHolderMatcher( final StringCursor cursor ) { if ( !cursor.shiftCursorToNextChar( '}' ) ) throw new RuntimeException( "Invalid expression!" ); final String placeholder = cursor.substringFromLastMark( 1 ); if ( cursor.hasNext() ) { final char nextChar = cursor.next(); patternMatchers.add( new PlaceHolderMatcher( placeholder, nextChar ) ); } else patternMatchers.add( new PlaceHolderForAnyStringUntilEndMatcher( placeholder, doNotIgnoreSlashes ) ); } }
public void compile( final String string ) { final StringCursor cursor = new StringCursor( string ); while ( cursor.hasNext() ) compile( cursor, cursor.next() ); if ( remainsUnparsedDataInCursor ) patternMatchers.add( new EqualsMatcher( cursor.substringFromLastMark() ) ); patternMatchers.add( new EndOfStringMatcher() ); }
@Override public boolean matches( final StringCursor string , final Map<String, String> foundParameters ) { string.mark(); string.end(); foundParameters.put(placeholder, string.substringFromLastMark()); return true; }
private StringCursor decode( String authString ) { try { final ByteBuffer decode = FlexBase64.decode( authString ); final String string = new String( decode.array(), decode.arrayOffset(), decode.limit(), StandardCharsets.UTF_8 ); return new StringCursor( string ); } catch ( final IOException cause ) { log.warn( "Ignoring exception during Base64 decoding.", cause ); return null; } }
@Override public boolean matches( final StringCursor string , final Map<String, String> foundParameters ) { string.end(); return true; }
@Override public boolean matches( final StringCursor string , final Map<String, String> foundParameters ) { return !string.hasNext(); }
@Override public boolean matches( final StringCursor string, final Map<String, String> foundParameters ) { string.reset(); for ( final Matcher matcher : patternMatchers ) if ( !matcher.matches( string, foundParameters ) ) return false; return true; }
static Tuple<String, String> fixContentType( String contentType, String defaultEncoding ){ if ( contentType == null ) return Tuple.empty(); final StringCursor cursor = new StringCursor(contentType); if ( cursor.shiftCursorToNextChar( ';' ) ) { contentType = cursor.substringFromLastMark( 1 ); cursor.mark(1); cursor.end(); defaultEncoding = cursor.substringFromLastMark(); } return Tuple.of( contentType, defaultEncoding ); } }
public boolean matches( final String string, final Map<String, String> foundParameters ) { return matches( new StringCursor( string ), foundParameters ); }
private StringCursor getAuthenticationHeader( HttpServerExchange exchange ) { final HeaderValues authHeaders = exchange.getRequestHeaders().get( Headers.AUTHORIZATION ); StringCursor headerValue = null; if( authHeaders != null ) for ( final String value : authHeaders ) if ( value.startsWith( BASIC_PREFIX ) ) headerValue = new StringCursor( value ); return headerValue; }