@Test(expectedExceptions = IllegalArgumentException.class) public void rejectsInvalidContentLength() { HttpResponse.response() .addHeader(CONTENT_LENGTH, "foo") .ensureContentLengthIsValid() .build(); }
@Test(expectedExceptions = IllegalArgumentException.class) public void rejectsMultipleContentLengthInSingleHeader() { HttpResponse.response() .addHeader(CONTENT_LENGTH, "15, 16") .ensureContentLengthIsValid() .build(); }
@Test(expectedExceptions = IllegalArgumentException.class) public void rejectsMultipleContentLength() { HttpResponse.response() .addHeader(CONTENT_LENGTH, "15") .addHeader(CONTENT_LENGTH, "16") .ensureContentLengthIsValid() .build(); }
/** * 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 HttpResponse build() { if (validate) { ensureContentLengthIsValid(); } return new HttpResponse(this); }
/** * Throws an exception if there are multiple content-length or if the content-length is not an integer. * * @return {@code this} */ public Builder validateContentLength() { ensureContentLengthIsValid(); return this; }