@Override public int size() { return headers.size(); } };
@Override public Http2Headers decodeHeaders(int streamId, ByteBuf headerBlock) throws Http2Exception { try { final Http2Headers headers = newHeaders(); hpackDecoder.decode(streamId, headerBlock, headers, validateHeaders); headerArraySizeAccumulator = HEADERS_COUNT_WEIGHT_NEW * headers.size() + HEADERS_COUNT_WEIGHT_HISTORICAL * headerArraySizeAccumulator; return headers; } catch (Http2Exception e) { throw e; } catch (Throwable e) { // Default handler for any other types of errors that may have occurred. For example, // the Header builder throws IllegalArgumentException if the key or value was invalid // for any reason (e.g. the key was an invalid pseudo-header). throw connectionError(COMPRESSION_ERROR, e, e.getMessage()); } }
/** * Converts the specified Netty HTTP/2 into Armeria HTTP/2 headers. */ public static HttpHeaders toArmeria(Http2Headers headers, boolean endOfStream) { final HttpHeaders converted = new DefaultHttpHeaders(false, headers.size(), endOfStream); StringJoiner cookieJoiner = null; for (Entry<CharSequence, CharSequence> e : headers) { final AsciiString name = HttpHeaderNames.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; }
@Override public int size() { return headers.size(); } };
@Override public int size() { return delegate.size(); }
@Override public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception { log.debug("onPushPromiseRead, streamId: {}, promisedStreamId: {}, headers size: {}", streamId, promisedStreamId, headers.size()); }
@Override public Http2Headers decodeHeaders(int streamId, ByteBuf headerBlock) throws Http2Exception { try { final Http2Headers headers = newHeaders(); hpackDecoder.decode(streamId, headerBlock, headers, validateHeaders); headerArraySizeAccumulator = HEADERS_COUNT_WEIGHT_NEW * headers.size() + HEADERS_COUNT_WEIGHT_HISTORICAL * headerArraySizeAccumulator; return headers; } catch (Http2Exception e) { throw e; } catch (Throwable e) { // Default handler for any other types of errors that may have occurred. For example, // the Header builder throws IllegalArgumentException if the key or value was invalid // for any reason (e.g. the key was an invalid pseudo-header). throw connectionError(COMPRESSION_ERROR, e, e.getMessage()); } }
@Override public Http2Headers decodeHeaders(int streamId, ByteBuf headerBlock) throws Http2Exception { try { final Http2Headers headers = newHeaders(); hpackDecoder.decode(streamId, headerBlock, headers, validateHeaders); headerArraySizeAccumulator = HEADERS_COUNT_WEIGHT_NEW * headers.size() + HEADERS_COUNT_WEIGHT_HISTORICAL * headerArraySizeAccumulator; return headers; } catch (Http2Exception e) { throw e; } catch (Throwable e) { // Default handler for any other types of errors that may have occurred. For example, // the Header builder throws IllegalArgumentException if the key or value was invalid // for any reason (e.g. the key was an invalid pseudo-header). throw connectionError(COMPRESSION_ERROR, e, e.getMessage()); } }
streamRequest.getEntityStream().setReader(reader); LOG.debug("Sent HTTP/2 HEADERS frame, stream={}, end={}, headers={}, padding={}bytes", new Object[] { streamId, NOT_END_STREAM, http2Headers.size(), NO_PADDING}); headersFuture = encoder.writeHeaders(ctx, streamId, http2Headers, NO_PADDING, NOT_END_STREAM, promise); headersFuture.addListener(future -> { final Http2Headers headers = NettyRequestAdapter.toHttp2Headers(restRequest); LOG.debug("Sent HTTP/2 HEADERS frame, stream={}, end={}, headers={}, padding={}bytes", new Object[] { streamId, NOT_END_STREAM, headers.size(), NO_PADDING}); headersFuture = encoder.writeHeaders(ctx, streamId, headers, NO_PADDING, NOT_END_STREAM, promise); headersFuture.addListener(future -> {
new Object[]{streamId, endOfStream, headers.size(), padding});