Builder ensureContentLengthIsValid() { List<String> contentLengths = headers.build().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)); } return this; }
/** * Builds a new full response based on the settings configured in this builder. * If {@code validate} is set to true: * <ul> * <li>an exception will be thrown if the content length is not an integer, or more than one content length exists</li> * </ul> * * @return a new full response */ public StreamingHttpResponse build() { if (validate) { ensureContentLengthIsValid(); } return new StreamingHttpResponse(this); }
/** * Creates an HTTP response builder with a given status and empty body. * * @param status response status * @return a new builder */ public static Builder response(HttpResponseStatus status) { return new Builder(status); }
/** * Creates an HTTP response builder with a status of 200 OK and empty body. * * @return a new builder */ public static Builder response() { return new Builder(); }
/** * Adds a response cookie (adds a new Set-Cookie header). * * @param name cookie name * @param value cookie value * @return {@code this} */ public Builder addCookie(String name, String value) { return addCookie(HttpCookie.cookie(name, value)); }
public Builder newBuilder() { return new Builder(this); }