/** * Copies this string removing white space characters from the beginning and end of the string, and tries not to * copy if possible. * * @param c The {@link CharSequence} to trim. * @return a new string with characters {@code <= \\u0020} removed from the beginning and the end. */ public static CharSequence trim(CharSequence c) { if (c.getClass() == AsciiString.class) { return ((AsciiString) c).trim(); } if (c instanceof String) { return ((String) c).trim(); } int start = 0, last = c.length() - 1; int end = last; while (start <= end && c.charAt(start) <= ' ') { start++; } while (end >= start && c.charAt(end) <= ' ') { end--; } if (start == 0 && end == last) { return c; } return c.subSequence(start, end); }
/** * Copies this string removing white space characters from the beginning and end of the string, and tries not to * copy if possible. * * @param c The {@link CharSequence} to trim. * @return a new string with characters {@code <= \\u0020} removed from the beginning and the end. */ public static CharSequence trim(CharSequence c) { if (c.getClass() == AsciiString.class) { return ((AsciiString) c).trim(); } if (c instanceof String) { return ((String) c).trim(); } int start = 0, last = c.length() - 1; int end = last; while (start <= end && c.charAt(start) <= ' ') { start++; } while (end >= start && c.charAt(end) <= ' ') { end--; } if (start == 0 && end == last) { return c; } return c.subSequence(start, end); }
/** * Copies this string removing white space characters from the beginning and end of the string, and tries not to * copy if possible. * * @param c The {@link CharSequence} to trim. * @return a new string with characters {@code <= \\u0020} removed from the beginning and the end. */ public static CharSequence trim(CharSequence c) { if (c.getClass() == AsciiString.class) { return ((AsciiString) c).trim(); } if (c instanceof String) { return ((String) c).trim(); } int start = 0, last = c.length() - 1; int end = last; while (start <= end && c.charAt(start) <= ' ') { start++; } while (end >= start && c.charAt(end) <= ' ') { end--; } if (start == 0 && end == last) { return c; } return c.subSequence(start, end); }
if (ignoreCase) { if ((end = AsciiString.indexOf(rawNext, ',', begin)) == -1) { if (contentEqualsIgnoreCase(trim(rawNext), expected)) { return true; if (contentEqualsIgnoreCase(trim(rawNext.subSequence(begin, end)), expected)) { return true; if (contentEqualsIgnoreCase(trim(rawNext.subSequence(begin, rawNext.length())), expected)) { return true; if (contentEquals(trim(rawNext), expected)) { return true; if (contentEquals(trim(rawNext.subSequence(begin, end)), expected)) { return true; if (contentEquals(trim(rawNext.subSequence(begin, rawNext.length())), expected)) { return true;
/** * Filter the {@link HttpHeaderNames#TE} header according to the * <a href="https://tools.ietf.org/html/rfc7540#section-8.1.2.2">special rules in the HTTP/2 RFC</a>. * @param entry An entry whose name is {@link HttpHeaderNames#TE}. * @param out the resulting HTTP/2 headers. */ private static void toHttp2HeadersFilterTE(Entry<CharSequence, CharSequence> entry, Http2Headers out) { if (indexOf(entry.getValue(), ',', 0) == -1) { if (contentEqualsIgnoreCase(trim(entry.getValue()), TRAILERS)) { out.add(TE, TRAILERS); } } else { List<CharSequence> teValues = unescapeCsvFields(entry.getValue()); for (CharSequence teValue : teValues) { if (contentEqualsIgnoreCase(trim(teValue), TRAILERS)) { out.add(TE, TRAILERS); break; } } } }
/** * Filter the {@link HttpHeaderNames#TE} header according to the * <a href="https://tools.ietf.org/html/rfc7540#section-8.1.2.2">special rules in the HTTP/2 RFC</a>. * @param entry An entry whose name is {@link HttpHeaderNames#TE}. * @param out the resulting HTTP/2 headers. */ private static void toHttp2HeadersFilterTE(Entry<CharSequence, CharSequence> entry, HttpHeaders out) { if (AsciiString.indexOf(entry.getValue(), ',', 0) == -1) { if (AsciiString.contentEqualsIgnoreCase(AsciiString.trim(entry.getValue()), HttpHeaderValues.TRAILERS)) { out.add(HttpHeaderNames.TE, HttpHeaderValues.TRAILERS.toString()); } } else { final List<CharSequence> teValues = StringUtil.unescapeCsvFields(entry.getValue()); for (CharSequence teValue : teValues) { if (AsciiString.contentEqualsIgnoreCase(AsciiString.trim(teValue), HttpHeaderValues.TRAILERS)) { out.add(HttpHeaderNames.TE, HttpHeaderValues.TRAILERS.toString()); break; } } } }
private static CharSequenceMap toLowercaseMap(Iterator<? extends CharSequence> valuesIter, int arraySizeHint) { final CharSequenceMap result = new CharSequenceMap(arraySizeHint); while (valuesIter.hasNext()) { final AsciiString lowerCased = HttpHeaderNames.of(valuesIter.next()).toLowerCase(); try { int index = lowerCased.forEachByte(FIND_COMMA); if (index != -1) { int start = 0; do { result.add(lowerCased.subSequence(start, index, false).trim(), EMPTY_STRING); start = index + 1; } while (start < lowerCased.length() && (index = lowerCased.forEachByte(start, lowerCased.length() - start, FIND_COMMA)) != -1); result.add(lowerCased.subSequence(start, lowerCased.length(), false).trim(), EMPTY_STRING); } else { result.add(lowerCased.trim(), EMPTY_STRING); } } catch (Exception e) { // This is not expect to happen because FIND_COMMA never throws but must be caught // because of the ByteProcessor interface. throw new IllegalStateException(e); } } return result; }
private static CharSequenceMap<AsciiString> toLowercaseMap(Iterator<? extends CharSequence> valuesIter, int arraySizeHint) { UnsupportedValueConverter<AsciiString> valueConverter = UnsupportedValueConverter.<AsciiString>instance(); CharSequenceMap<AsciiString> result = new CharSequenceMap<AsciiString>(true, valueConverter, arraySizeHint); while (valuesIter.hasNext()) { AsciiString lowerCased = AsciiString.of(valuesIter.next()).toLowerCase(); try { int index = lowerCased.forEachByte(FIND_COMMA); if (index != -1) { int start = 0; do { result.add(lowerCased.subSequence(start, index, false).trim(), EMPTY_STRING); start = index + 1; } while (start < lowerCased.length() && (index = lowerCased.forEachByte(start, lowerCased.length() - start, FIND_COMMA)) != -1); result.add(lowerCased.subSequence(start, lowerCased.length(), false).trim(), EMPTY_STRING); } else { result.add(lowerCased.trim(), EMPTY_STRING); } } catch (Exception e) { // This is not expect to happen because FIND_COMMA never throws but must be caught // because of the ByteProcessor interface. throw new IllegalStateException(e); } } return result; }
/** * Copies this string removing white space characters from the beginning and end of the string, and tries not to * copy if possible. * * @param c The {@link CharSequence} to trim. * @return a new string with characters {@code <= \\u0020} removed from the beginning and the end. */ public static CharSequence trim(CharSequence c) { if (c.getClass() == AsciiString.class) { return ((AsciiString) c).trim(); } if (c instanceof String) { return ((String) c).trim(); } int start = 0, last = c.length() - 1; int end = last; while (start <= end && c.charAt(start) <= ' ') { start++; } while (end >= start && c.charAt(end) <= ' ') { end--; } if (start == 0 && end == last) { return c; } return c.subSequence(start, end); }
/** * Copies this string removing white space characters from the beginning and end of the string, and tries not to * copy if possible. * * @param c The {@link CharSequence} to trim. * @return a new string with characters {@code <= \\u0020} removed from the beginning and the end. */ public static CharSequence trim(CharSequence c) { if (c.getClass() == AsciiString.class) { return ((AsciiString) c).trim(); } if (c instanceof String) { return ((String) c).trim(); } int start = 0, last = c.length() - 1; int end = last; while (start <= end && c.charAt(start) <= ' ') { start++; } while (end >= start && c.charAt(end) <= ' ') { end--; } if (start == 0 && end == last) { return c; } return c.subSequence(start, end); }
/** * Copies this string removing white space characters from the beginning and end of the string, and tries not to * copy if possible. * * @param c The {@link CharSequence} to trim. * @return a new string with characters {@code <= \\u0020} removed from the beginning and the end. */ public static CharSequence trim(CharSequence c) { if (c.getClass() == AsciiString.class) { return ((AsciiString) c).trim(); } if (c instanceof String) { return ((String) c).trim(); } int start = 0, last = c.length() - 1; int end = last; while (start <= end && c.charAt(start) <= ' ') { start++; } while (end >= start && c.charAt(end) <= ' ') { end--; } if (start == 0 && end == last) { return c; } return c.subSequence(start, end); }
/** * Copies this string removing white space characters from the beginning and end of the string, and tries not to * copy if possible. * * @param c The {@link CharSequence} to trim. * @return a new string with characters {@code <= \\u0020} removed from the beginning and the end. */ public static CharSequence trim(CharSequence c) { if (c.getClass() == AsciiString.class) { return ((AsciiString) c).trim(); } if (c instanceof String) { return ((String) c).trim(); } int start = 0, last = c.length() - 1; int end = last; while (start <= end && c.charAt(start) <= ' ') { start++; } while (end >= start && c.charAt(end) <= ' ') { end--; } if (start == 0 && end == last) { return c; } return c.subSequence(start, end); }
if (ignoreCase) { if ((end = AsciiString.indexOf(rawNext, ',', begin)) == -1) { if (contentEqualsIgnoreCase(trim(rawNext), expected)) { return true; if (contentEqualsIgnoreCase(trim(rawNext.subSequence(begin, end)), expected)) { return true; if (contentEqualsIgnoreCase(trim(rawNext.subSequence(begin, rawNext.length())), expected)) { return true; if (contentEquals(trim(rawNext), expected)) { return true; if (contentEquals(trim(rawNext.subSequence(begin, end)), expected)) { return true; if (contentEquals(trim(rawNext.subSequence(begin, rawNext.length())), expected)) { return true;
if (ignoreCase) { if ((end = AsciiString.indexOf(rawNext, ',', begin)) == -1) { if (contentEqualsIgnoreCase(trim(rawNext), expected)) { return true; if (contentEqualsIgnoreCase(trim(rawNext.subSequence(begin, end)), expected)) { return true; if (contentEqualsIgnoreCase(trim(rawNext.subSequence(begin, rawNext.length())), expected)) { return true; if (contentEquals(trim(rawNext), expected)) { return true; if (contentEquals(trim(rawNext.subSequence(begin, end)), expected)) { return true; if (contentEquals(trim(rawNext.subSequence(begin, rawNext.length())), expected)) { return true;
/** * Filter the {@link HttpHeaderNames#TE} header according to the * <a href="https://tools.ietf.org/html/rfc7540#section-8.1.2.2">special rules in the HTTP/2 RFC</a>. * @param entry An entry whose name is {@link HttpHeaderNames#TE}. * @param out the resulting HTTP/2 headers. */ private static void toHttp2HeadersFilterTE(Entry<CharSequence, CharSequence> entry, Http2Headers out) { if (indexOf(entry.getValue(), ',', 0) == -1) { if (contentEqualsIgnoreCase(trim(entry.getValue()), TRAILERS)) { out.add(TE, TRAILERS); } } else { List<CharSequence> teValues = unescapeCsvFields(entry.getValue()); for (CharSequence teValue : teValues) { if (contentEqualsIgnoreCase(trim(teValue), TRAILERS)) { out.add(TE, TRAILERS); break; } } } }
/** * Filter the {@link HttpHeaderNames#TE} header according to the * <a href="https://tools.ietf.org/html/rfc7540#section-8.1.2.2">special rules in the HTTP/2 RFC</a>. * @param entry An entry whose name is {@link HttpHeaderNames#TE}. * @param out the resulting HTTP/2 headers. */ private static void toHttp2HeadersFilterTE(Entry<CharSequence, CharSequence> entry, Http2Headers out) { if (indexOf(entry.getValue(), ',', 0) == -1) { if (contentEqualsIgnoreCase(trim(entry.getValue()), TRAILERS)) { out.add(TE, TRAILERS); } } else { List<CharSequence> teValues = unescapeCsvFields(entry.getValue()); for (CharSequence teValue : teValues) { if (contentEqualsIgnoreCase(trim(teValue), TRAILERS)) { out.add(TE, TRAILERS); break; } } } }
private static CharSequenceMap<AsciiString> toLowercaseMap(Iterator<? extends CharSequence> valuesIter, int arraySizeHint) { UnsupportedValueConverter<AsciiString> valueConverter = UnsupportedValueConverter.<AsciiString>instance(); CharSequenceMap<AsciiString> result = new CharSequenceMap<AsciiString>(true, valueConverter, arraySizeHint); while (valuesIter.hasNext()) { AsciiString lowerCased = AsciiString.of(valuesIter.next()).toLowerCase(); try { int index = lowerCased.forEachByte(FIND_COMMA); if (index != -1) { int start = 0; do { result.add(lowerCased.subSequence(start, index, false).trim(), EMPTY_STRING); start = index + 1; } while (start < lowerCased.length() && (index = lowerCased.forEachByte(start, lowerCased.length() - start, FIND_COMMA)) != -1); result.add(lowerCased.subSequence(start, lowerCased.length(), false).trim(), EMPTY_STRING); } else { result.add(lowerCased.trim(), EMPTY_STRING); } } catch (Exception e) { // This is not expect to happen because FIND_COMMA never throws but must be caught // because of the ByteProcessor interface. throw new IllegalStateException(e); } } return result; }
private static CharSequenceMap<AsciiString> toLowercaseMap(Iterator<? extends CharSequence> valuesIter, int arraySizeHint) { UnsupportedValueConverter<AsciiString> valueConverter = UnsupportedValueConverter.<AsciiString>instance(); CharSequenceMap<AsciiString> result = new CharSequenceMap<AsciiString>(true, valueConverter, arraySizeHint); while (valuesIter.hasNext()) { AsciiString lowerCased = AsciiString.of(valuesIter.next()).toLowerCase(); try { int index = lowerCased.forEachByte(FIND_COMMA); if (index != -1) { int start = 0; do { result.add(lowerCased.subSequence(start, index, false).trim(), EMPTY_STRING); start = index + 1; } while (start < lowerCased.length() && (index = lowerCased.forEachByte(start, lowerCased.length() - start, FIND_COMMA)) != -1); result.add(lowerCased.subSequence(start, lowerCased.length(), false).trim(), EMPTY_STRING); } else { result.add(lowerCased.trim(), EMPTY_STRING); } } catch (Exception e) { // This is not expect to happen because FIND_COMMA never throws but must be caught // because of the ByteProcessor interface. throw new IllegalStateException(e); } } return result; }
private boolean isUpgradeRequest(FullHttpRequest request) { if (!request.decoderResult().isSuccess()) { return false; } CharSequence connectionHeaderValue = request.headers().get(HttpHeaderNames.CONNECTION); if (connectionHeaderValue == null) { return false; } AsciiString connectionHeaderString = new AsciiString(connectionHeaderValue); AsciiString[] connectionHeaderFields = connectionHeaderString.toLowerCase().split(','); boolean hasUpgradeField = false; AsciiString upgradeValue = HttpHeaderValues.UPGRADE.toLowerCase(); for (AsciiString s : connectionHeaderFields) { if (upgradeValue.equals(s.trim())) { hasUpgradeField = true; break; } } if (!hasUpgradeField) { return false; } if (!request.headers().contains( HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET, true)) { return false; } return request.uri().equals(websocketPath); }
private boolean isUpgradeRequest(FullHttpRequest request) { if (!request.decoderResult().isSuccess()) { return false; } CharSequence connectionHeaderValue = request.headers().get(HttpHeaderNames.CONNECTION); if (connectionHeaderValue == null) { return false; } AsciiString connectionHeaderString = new AsciiString(connectionHeaderValue); AsciiString[] connectionHeaderFields = connectionHeaderString.toLowerCase().split(','); boolean hasUpgradeField = false; AsciiString upgradeValue = HttpHeaderValues.UPGRADE.toLowerCase(); for (AsciiString s : connectionHeaderFields) { if (upgradeValue.equals(s.trim())) { hasUpgradeField = true; break; } } if (!hasUpgradeField) { return false; } if (!request.headers().contains( HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET, true)) { return false; } return request.uri().equals(websocketPath); }