/** * Converts the {@link AggregatedHttpMessage} into a new {@link HttpRequest} and closes the stream. */ static HttpRequest of(AggregatedHttpMessage message) { return of(message.headers(), message.content(), message.trailingHeaders()); }
private static HttpHeaders fillAdditionalHeaders(HttpHeaders headers, HttpHeaders additionalHeaders) { if (!additionalHeaders.isEmpty()) { if (headers.isImmutable()) { // All headers are already validated. final HttpHeaders temp = headers; headers = new DefaultHttpHeaders(false, temp.size() + additionalHeaders.size()); headers.set(temp); } headers.setAllIfAbsent(additionalHeaders); } return headers; }
/** * Creates a new HTTP response of the specified {@link HttpStatus} and closes the stream. * * @param mediaType the {@link MediaType} of the response content * @param content the content of the response * @param offset the start offset of {@code content} * @param length the length of {@code content} */ static HttpResponse of(HttpStatus status, MediaType mediaType, byte[] content, int offset, int length) { return of(status, mediaType, HttpData.of(content, offset, length)); }
/** * Returns new HTTP headers with two entries. */ static HttpHeaders of(AsciiString name1, String value1, AsciiString name2, String value2) { return new DefaultHttpHeaders().add(name1, value1).add(name2, value2); }
@Override public HttpHeaders status(int statusCode) { final HttpStatus status = this.status = HttpStatus.valueOf(statusCode); set(HttpHeaderNames.STATUS, status.codeAsText()); return this; }
/** * Returns a fake {@link Channel} which is required internally when creating a context. */ protected final Channel fakeChannel() { if (channel == null) { channel = new FakeChannel(eventLoop(), alloc(), remoteAddress(), localAddress()); } return channel; }
/** * Returns a {@link ClosedSessionException} which may be a singleton or a new instance, depending on * whether {@linkplain Flags#verboseExceptions() the verbose exception mode} is enabled. */ public static ClosedSessionException get() { return Flags.verboseExceptions() ? new ClosedSessionException() : INSTANCE; }
/** * Returns new HTTP headers with three entries. */ static HttpHeaders of(AsciiString name1, String value1, AsciiString name2, String value2, AsciiString name3, String value3) { return new DefaultHttpHeaders().add(name1, value1).add(name2, value2) .add(name3, value3); }
/** * Returns new HTTP headers with four entries. */ static HttpHeaders of(AsciiString name1, String value1, AsciiString name2, String value2, AsciiString name3, String value3, AsciiString name4, String value4) { return new DefaultHttpHeaders().add(name1, value1).add(name2, value2) .add(name3, value3).add(name4, value4); }