Example usage for io.netty.util AsciiString equals

List of usage examples for io.netty.util AsciiString equals

Introduction

In this page you can find the example usage for io.netty.util AsciiString equals.

Prototype

@Override
    public boolean equals(Object obj) 

Source Link

Usage

From source file:com.linecorp.armeria.internal.ArmeriaHttpUtil.java

License:Apache License

/**
 * Converts the specified Netty HTTP/2 into Armeria HTTP/2 headers.
 *//* w  w w. j  a  v a 2s  .co m*/
public static HttpHeaders toArmeria(Http2Headers headers) {
    final HttpHeaders converted = new DefaultHttpHeaders(false, headers.size());
    StringJoiner cookieJoiner = null;
    for (Entry<CharSequence, CharSequence> e : headers) {
        final AsciiString name = AsciiString.of(e.getKey());
        final CharSequence value = e.getValue();

        // Cookies must be concatenated into a single octet string.
        // https://tools.ietf.org/html/rfc7540#section-8.1.2.5
        if (name.equals(HttpHeaderNames.COOKIE)) {
            if (cookieJoiner == null) {
                cookieJoiner = new StringJoiner(COOKIE_SEPARATOR);
            }
            COOKIE_SPLITTER.split(value).forEach(cookieJoiner::add);
        } else {
            converted.add(name, convertHeaderValue(name, value));
        }
    }

    if (cookieJoiner != null && cookieJoiner.length() != 0) {
        converted.add(HttpHeaderNames.COOKIE, cookieJoiner.toString());
    }

    return converted;
}

From source file:com.linecorp.armeria.internal.ArmeriaHttpUtil.java

License:Apache License

/**
 * Converts the specified Netty HTTP/1 headers into Armeria HTTP/2 headers.
 *///from ww  w. j  av  a 2s .  co  m
public static void toArmeria(io.netty.handler.codec.http.HttpHeaders inHeaders, HttpHeaders out) {
    final 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.
    final CharSequenceMap connectionBlacklist = toLowercaseMap(
            inHeaders.valueCharSequenceIterator(HttpHeaderNames.CONNECTION), 8);
    StringJoiner cookieJoiner = null;
    while (iter.hasNext()) {
        final 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)) {
            continue;
        }

        // https://tools.ietf.org/html/rfc7540#section-8.1.2.2 makes a special exception for TE
        if (aName.equals(HttpHeaderNames.TE)) {
            toHttp2HeadersFilterTE(entry, out);
            continue;
        }

        // Cookies must be concatenated into a single octet string.
        // https://tools.ietf.org/html/rfc7540#section-8.1.2.5
        final CharSequence value = entry.getValue();
        if (aName.equals(HttpHeaderNames.COOKIE)) {
            if (cookieJoiner == null) {
                cookieJoiner = new StringJoiner(COOKIE_SEPARATOR);
            }
            COOKIE_SPLITTER.split(value).forEach(cookieJoiner::add);
        } else {
            out.add(aName, convertHeaderValue(aName, value));
        }
    }

    if (cookieJoiner != null && cookieJoiner.length() != 0) {
        out.add(HttpHeaderNames.COOKIE, cookieJoiner.toString());
    }
}

From source file:io.grpc.netty.NettyServerHandler.java

License:Apache License

private String getOrUpdateAuthority(AsciiString authority) {
    if (authority == null) {
        return null;
    } else if (!authority.equals(lastKnownAuthority)) {
        lastKnownAuthority = authority;// ww  w .ja  v  a  2  s .  co m
    }

    // AsciiString.toString() is internally cached, so subsequent calls will not
    // result in recomputing the String representation of lastKnownAuthority.
    return lastKnownAuthority.toString();
}