All Downloads are FREE. Search and download functionalities are using the official Maven repository.

im.toss.http.parser.Rfc7230TokenValidator Maven / Gradle / Ivy

The newest version!
package im.toss.http.parser;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Validates a token
 *
 * @see Section 3.2.6 of RFC 7230
 */
class Rfc7230TokenValidator extends AbstractTokenValidator {

    /**
     * Validates a token
     *
     * @param  token  a token. Must not be null.
     * @throws TokenValidationException if the token is not valid
     * @see Section 3.2.6 of RFC 7230
     */
    @Override
    public void validate(String token) {
        Pattern p = Pattern.compile("[^-A-Za-z0-9!#$%&'*+.^_`|~ \"\\\\]");
        Matcher matcher = p.matcher(token);
        if (matcher.find()) {
            throw new TokenValidationException(unexpectedCharacterError(matcher.group(),
                                                                        matcher.start()));
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy