void ensureContentLengthIsValid() { List<String> contentLengths = headers().getAll(CONTENT_LENGTH); checkArgument(contentLengths.size() <= 1, "Duplicate Content-Length found. %s", contentLengths); if (contentLengths.size() == 1) { checkArgument(isInteger(contentLengths.get(0)), "Invalid Content-Length found. %s", contentLengths.get(0)); } }
/** * Sets the (only) value for the header with the specified name. * <p/> * All existing values for the same header will be removed. * * @param name The name of the header * @param value The value of the header * @return {@code this} */ public SELF header(CharSequence name, Instant value) { checkNotCookie(name); headers.set(name, checkNotNull(value)); return (SELF) this; }
/** * Adds a new header with the specified {@code name} and {@code value}. * <p/> * Will not replace any existing values for the header. * * @param name The name of the header * @param values The value of the header * @return {@code this} */ public SELF addHeader(CharSequence name, Iterable<?> values) { checkNotCookie(name); headers.add(name, values); return (SELF) this; }
/** * Sets the message body. As the content length is known, this header will also be set. * * @param content message body content. * @return {@code this} */ public SELF body(ByteBuffer content) { return body(Unpooled.copiedBuffer(content)); }
/** * Sets the (only) value for the header with the specified name. * <p/> * All existing values for the same header will be removed. * * @param name The name of the header * @param values The value of the header * @return {@code this} */ public SELF header(CharSequence name, Iterable<?> values) { checkNotCookie(name); headers.set(name, values); return (SELF) this; }
/** * Sets the message body. As the content length is known, this header will also be set. * * @param content message body content. * @return {@code this} */ public SELF body(byte[] content) { return body(Unpooled.copiedBuffer(content).retain()); }
/** * Adds a new header with the specified {@code name} and {@code value}. * <p/> * Will not replace any existing values for the header. * * @param name The name of the header * @param value The value of the header * @return {@code this} */ public SELF addHeader(CharSequence name, String value) { checkNotCookie(name); headers.add(name, value); return (SELF) this; }
/** * Sets the message body. * * @param content message body content * @return {@code this} */ public SELF body(Observable<ByteBuf> content) { return body(new HttpMessageBody(content)); }
/** * Sets the (only) value for the header with the specified name. * <p/> * All existing values for the same header will be removed. * * @param name The name of the header * @param value The value of the header * @return {@code this} */ public SELF header(CharSequence name, String value) { checkNotCookie(name); headers.set(name, checkNotNull(value)); return (SELF) this; }
/** * Sets the (only) value for the header with the specified name. * <p/> * All existing values for the same header will be removed. * * @param name The name of the header * @param value The value of the header * @return {@code this} */ public SELF header(CharSequence name, Object value) { checkNotCookie(name); headers.set(name, checkNotNull(value)); return (SELF) this; }
/** * Adds a new header with the specified {@code name} and {@code value}. * <p/> * Will not replace any existing values for the header. * * @param name The name of the header * @param value The value of the header * @return {@code this} */ public SELF addHeader(CharSequence name, Object value) { checkNotCookie(name); headers.add(name, value); return (SELF) this; }
public SELF headers(HttpHeader... headers) { for (HttpHeader header : headers) { checkNotCookie(header.name()); this.headers.set(header.name(), header.value()); } return (SELF) this; }