Java Code Examples for io.netty.util.AsciiString#byteAt()
The following examples show how to use
io.netty.util.AsciiString#byteAt() .
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 |
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 |
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: Http2Headers.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
/** * Indicates whether the specified header follows the pseudo-header format (begins with ':' character) * * @return {@code true} if the header follow the pseudo-header format */ public static boolean hasPseudoHeaderFormat(CharSequence headerName) { if (headerName instanceof AsciiString) { final AsciiString asciiHeaderName = (AsciiString) headerName; return asciiHeaderName.length() > 0 && asciiHeaderName.byteAt(0) == PSEUDO_HEADER_PREFIX_BYTE; } else { return headerName.length() > 0 && headerName.charAt(0) == PSEUDO_HEADER_PREFIX; } }
Example 4
Source File: IOUtil.java From spring-boot-protocol with Apache License 2.0 | 4 votes |
public static int getInt(AsciiString memory) { return (memory.byteAt(0) & 0xff) << 24 | (memory.byteAt(1) & 0xff) << 16 | (memory.byteAt(2) & 0xff) << 8 | memory.byteAt(3) & 0xff; }
Example 5
Source File: HttpHeadersBase.java From armeria with Apache License 2.0 | 4 votes |
@Override boolean isFirstGroup(AsciiString name) { // Pseudo headers must come first during iteration. return !name.isEmpty() && name.byteAt(0) == ':'; }