Java Code Examples for io.netty.util.AsciiString#contentEqualsIgnoreCase()

The following examples show how to use io.netty.util.AsciiString#contentEqualsIgnoreCase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReadOnlyHttp2Headers.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
private void calculateNext() {
    for (; i < current.length; i += 2) {
        AsciiString roName = current[i];
        if (roName.hashCode() == nameHash && roName.contentEqualsIgnoreCase(name)) {
            next = current[i + 1];
            i += 2;
            return;
        }
    }
    if (i >= current.length && current == pseudoHeaders) {
        i = 0;
        current = otherHeaders;
        calculateNext();
    } else {
        next = null;
    }
}
 
Example 2
Source File: Http2RequestDecoder.java    From armeria with Apache License 2.0 6 votes vote down vote up
private boolean handle100Continue(ChannelHandlerContext ctx, int streamId, Http2Headers headers) {
    final CharSequence expectValue = headers.get(HttpHeaderNames.EXPECT);
    if (expectValue == null) {
        // No 'expect' header.
        return true;
    }

    // '100-continue' is the only allowed expectation.
    if (!AsciiString.contentEqualsIgnoreCase(HttpHeaderValues.CONTINUE, expectValue)) {
        return false;
    }

    // Send a '100 Continue' response.
    writer.writeHeaders(
            ctx, streamId,
            new DefaultHttp2Headers(false).status(HttpStatus.CONTINUE.codeAsText()),
            0, false, ctx.voidPromise());

    // Remove the 'expect' header so that it's handled in a way invisible to a Service.
    headers.remove(HttpHeaderNames.EXPECT);
    return true;
}
 
Example 3
Source File: ArmeriaHttpUtil.java    From armeria with Apache License 2.0 6 votes vote down vote up
/**
 * 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 the entry whose name is {@link HttpHeaderNames#TE}.
 * @param out the resulting HTTP/2 headers.
 */
private static void toHttp2HeadersFilterTE(Entry<CharSequence, CharSequence> entry,
                                           HttpHeadersBuilder 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;
            }
        }
    }
}
 
Example 4
Source File: ReadOnlyHttp2Headers.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private static boolean contains(CharSequence name, int nameHash, CharSequence value, int valueHash,
                                HashingStrategy<CharSequence> hashingStrategy, AsciiString[] headers) {
    final int headersEnd = headers.length - 1;
    for (int i = 0; i < headersEnd; i += 2) {
        AsciiString roName = headers[i];
        AsciiString roValue = headers[i + 1];
        if (roName.hashCode() == nameHash && roValue.hashCode() == valueHash &&
            roName.contentEqualsIgnoreCase(name) && hashingStrategy.equals(roValue, value)) {
            return true;
        }
    }
    return false;
}
 
Example 5
Source File: HttpConversionUtil.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
public static void toHttp2Headers(HttpHeaders inHeaders, Http2Headers out) {
    Iterator<Entry<CharSequence, CharSequence>> iter = inHeaders.iteratorCharSequence();
    // Choose 8 as a default size because it is unlikely we will see more than 4 Connection headers values, but
    // still allowing for "enough" space in the map to reduce the chance of hash code collision.
    CharSequenceMap<AsciiString> connectionBlacklist =
        toLowercaseMap(inHeaders.valueCharSequenceIterator(CONNECTION), 8);
    while (iter.hasNext()) {
        Entry<CharSequence, CharSequence> entry = iter.next();
        final AsciiString aName = AsciiString.of(entry.getKey()).toLowerCase();
        if (!HTTP_TO_HTTP2_HEADER_BLACKLIST.contains(aName) && !connectionBlacklist.contains(aName)) {
            // https://tools.ietf.org/html/rfc7540#section-8.1.2.2 makes a special exception for TE
            if (aName.contentEqualsIgnoreCase(TE)) {
                toHttp2HeadersFilterTE(entry, out);
            } else if (aName.contentEqualsIgnoreCase(COOKIE)) {
                AsciiString value = AsciiString.of(entry.getValue());
                // split up cookies to allow for better compression
                // https://tools.ietf.org/html/rfc7540#section-8.1.2.5
                try {
                    int index = value.forEachByte(FIND_SEMI_COLON);
                    if (index != -1) {
                        int start = 0;
                        do {
                            out.add(COOKIE, value.subSequence(start, index, false));
                            // skip 2 characters "; " (see https://tools.ietf.org/html/rfc6265#section-4.2.1)
                            start = index + 2;
                        } while (start < value.length() &&
                                (index = value.forEachByte(start, value.length() - start, FIND_SEMI_COLON)) != -1);
                        if (start >= value.length()) {
                            throw new IllegalArgumentException("cookie value is of unexpected format: " + value);
                        }
                        out.add(COOKIE, value.subSequence(start, value.length(), false));
                    } else {
                        out.add(COOKIE, value);
                    }
                } catch (Exception e) {
                    // This is not expect to happen because FIND_SEMI_COLON never throws but must be caught
                    // because of the ByteProcessor interface.
                    throw new IllegalStateException(e);
                }
            } else {
                out.add(aName, entry.getValue());
            }
        }
    }
}
 
Example 6
Source File: CharSequenceValueConverter.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
public boolean convertToBoolean(CharSequence value) {
    return AsciiString.contentEqualsIgnoreCase(value, TRUE_ASCII);
}
 
Example 7
Source File: ArmeriaHttpUtil.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
public boolean equals(AsciiString a, AsciiString b) {
    return a.contentEqualsIgnoreCase(b);
}
 
Example 8
Source File: HttpHeadersBase.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
boolean nameEquals(AsciiString a, CharSequence b) {
    return a.contentEqualsIgnoreCase(b);
}