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

The following examples show how to use io.netty.util.AsciiString#isEmpty() . 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 static void validateHeaders(AsciiString[] pseudoHeaders, AsciiString... otherHeaders) {
    // We are only validating values... so start at 1 and go until end.
    for (int i = 1; i < pseudoHeaders.length; i += 2) {
        // pseudoHeaders names are only set internally so they are assumed to be valid.
        if (pseudoHeaders[i] == null) {
            throw new IllegalArgumentException("pseudoHeaders value at index " + i + " is null");
        }
    }

    boolean seenNonPseudoHeader = false;
    final int otherHeadersEnd = otherHeaders.length - 1;
    for (int i = 0; i < otherHeadersEnd; i += 2) {
        AsciiString name = otherHeaders[i];
        HTTP2_NAME_VALIDATOR.validateName(name);
        if (!seenNonPseudoHeader && !name.isEmpty() && name.byteAt(0) != PSEUDO_HEADER_TOKEN) {
            seenNonPseudoHeader = true;
        } else if (seenNonPseudoHeader && !name.isEmpty() && name.byteAt(0) == PSEUDO_HEADER_TOKEN) {
            throw new IllegalArgumentException(
                 "otherHeaders name at index " + i + " is a pseudo header that appears after non-pseudo headers.");
        }
        if (otherHeaders[i + 1] == null) {
            throw new IllegalArgumentException("otherHeaders value at index " + (i + 1) + " is null");
        }
    }
}
 
Example 2
Source File: TomcatService.java    From armeria with Apache License 2.0 6 votes vote down vote up
private static void convertHeaders(HttpHeaders headers, MimeHeaders cHeaders) {
    if (headers.isEmpty()) {
        return;
    }

    for (Entry<AsciiString, String> e : headers) {
        final AsciiString k = e.getKey();
        final String v = e.getValue();

        if (k.isEmpty() || k.byteAt(0) == ':') {
            continue;
        }

        final MessageBytes cValue = cHeaders.addValue(k.array(), k.arrayOffset(), k.length());
        final byte[] valueBytes = v.getBytes(StandardCharsets.US_ASCII);
        cValue.setBytes(valueBytes, 0, valueBytes.length);
    }
}
 
Example 3
Source File: HttpHeaderNames.java    From armeria with Apache License 2.0 5 votes vote down vote up
private static AsciiString validate(AsciiString name) {
    if (name.isEmpty()) {
        throw new IllegalArgumentException("malformed header name: <EMPTY>");
    }

    if (!Flags.validateHeaders()) {
        return name;
    }

    final int lastIndex;
    try {
        lastIndex = name.forEachByte(value -> {
            if (value > LAST_PROHIBITED_NAME_CHAR) {
                // Definitely valid.
                return true;
            }

            return !PROHIBITED_NAME_CHARS.get(value);
        });
    } catch (Exception e) {
        throw new Error(e);
    }

    if (lastIndex >= 0) {
        throw new IllegalArgumentException(malformedHeaderNameMessage(name));
    }

    return name;
}
 
Example 4
Source File: GrpcHttp2HeadersUtils.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
protected static boolean isPseudoHeader(AsciiString str) {
  return !str.isEmpty() && str.charAt(0) == ':';
}
 
Example 5
Source File: HttpHeadersBase.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
boolean isFirstGroup(AsciiString name) {
    // Pseudo headers must come first during iteration.
    return !name.isEmpty() && name.byteAt(0) == ':';
}
 
Example 6
Source File: GrpcHttp2HeadersUtils.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
protected static boolean isPseudoHeader(AsciiString str) {
  return !str.isEmpty() && str.charAt(0) == ':';
}