@Test public void removesNullValues() { HttpHeaders headers = new Builder() .add("header1", asList("val1", null, "val2")) .build(); assertThat(headers, contains(header("header1", "val1"), header("header1", "val2"))); }
private static HttpHeaders toStyxHeaders(com.github.tomakehurst.wiremock.http.HttpHeaders headers) { HttpHeaders.Builder builder = new HttpHeaders.Builder(); if (headers != null) { headers.all().forEach(header -> builder.add(header.key(), header.values())); } return builder.build(); }
/** * 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 Builder addHeader(CharSequence name, Object value) { headers.add(name, value); return 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 Builder addHeader(CharSequence name, Object value) { headers.add(name, value); return 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 Builder addHeader(CharSequence name, Object value) { this.headers.add(name, value); return 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 Builder addHeader(CharSequence name, Object value) { headers.add(name, value); return 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 Builder addHeader(CharSequence name, Object value) { checkNotCookie(name); this.headers.add(name, value); return 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 Builder addHeader(CharSequence name, Object value) { checkNotCookie(name); this.headers.add(name, value); return 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 Builder addHeader(CharSequence name, Object value) { headers.add(name, value); return this; }
@Test(expectedExceptions = NullPointerException.class) public void doesNotAllowNullName() { new HttpHeaders.Builder() .add(null, "value") .build(); }
@Test(expectedExceptions = NullPointerException.class) public void doesNotAllowNullValue() { new HttpHeaders.Builder() .add("header1", (String) null) .build(); }
/** * Set the response to be chunked. * * @return {@code this} */ public SELF chunked() { headers().add(TRANSFER_ENCODING, CHUNKED); headers().remove(CONTENT_LENGTH); return (SELF) this; }
/** * Makes this response chunked. * * @return {@code this} */ public Builder setChunked() { headers.add(TRANSFER_ENCODING, CHUNKED); headers.remove(CONTENT_LENGTH); return this; }
@Test public void setsHeaders() { HttpHeaders newHeaders = new HttpHeaders.Builder() .add("foo", "bar") .build(); HttpHeaders headers = new HttpHeaders.Builder(newHeaders) .build(); assertThat(headers, contains(header("foo", "bar"))); }
@Test public void transformerSetsHeaders() { LiveHttpResponse response = response().build() .newBuilder() .headers(new HttpHeaders.Builder().add("X-Styx-ID", "z").build()) .build(); assertEquals(response.header("X-Styx-ID"), Optional.of("z")); }
/** * Enables Keep-Alive. * * @return {@code this} */ public Builder enableKeepAlive() { this.headers().add(CONNECTION, KEEP_ALIVE); return this; }
/** * Makes this response chunked. * * @return {@code this} */ public Builder setChunked() { headers.add(TRANSFER_ENCODING, CHUNKED); headers.remove(CONTENT_LENGTH); return this; }
/** * Makes this response chunked. * * @return {@code this} */ public Builder setChunked() { headers.add(TRANSFER_ENCODING, CHUNKED); headers.remove(CONTENT_LENGTH); return this; }
/** * Makes this response chunked. * * @return {@code this} */ public Builder setChunked() { headers.add(TRANSFER_ENCODING, CHUNKED); headers.remove(CONTENT_LENGTH); return this; }