com.hotels.styx.api.HttpResponse.headers()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(4.8k)|赞(0)|评价(0)|浏览(76)

本文整理了Java中com.hotels.styx.api.HttpResponse.headers()方法的一些代码示例,展示了HttpResponse.headers()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.headers()方法的具体详情如下:
包路径:com.hotels.styx.api.HttpResponse
类名称:HttpResponse
方法名:headers

HttpResponse.headers介绍

[英]Return all the headers in this response.
[中]返回此响应中的所有标题。

代码示例

代码示例来源:origin: HotelsDotCom/styx

/**
 * Creates a new {@link Builder} object from an existing {@link LiveHttpResponse} object.
 * Similar to {@link this.newBuilder} method.
 *
 * @param response a full HTTP response instance
 */
public Builder(HttpResponse response) {
  this.status = response.status();
  this.version = response.version();
  this.headers = response.headers().newBuilder();
  this.body = response.body();
}

代码示例来源:origin: com.hotels.styx/styx-api

public Builder(HttpResponse response, Observable<ByteBuf> decoded) {
  this.status = statusWithCode(response.status().code());
  this.version = httpVersion(response.version().toString());
  this.headers = response.headers().newBuilder();
  this.body = decoded;
  this.cookies = new ArrayList<>(response.cookies());
}

代码示例来源:origin: com.hotels.styx/styx-api

public Builder(HttpResponse response, byte[] encodedBody) {
  this.status = statusWithCode(response.status().code());
  this.version = httpVersion(response.version().toString());
  this.headers = response.headers().newBuilder();
  this.body = encodedBody;
  this.cookies = new ArrayList<>(response.cookies());
}

代码示例来源:origin: HotelsDotCom/styx

@Test
public void addsHeaderValue() {
  HttpResponse response = HttpResponse.response()
      .header("name", "value1")
      .addHeader("name", "value2")
      .build();
  assertThat(response.headers(), hasItem(header("name", "value1")));
  assertThat(response.headers(), hasItem(header("name", "value2")));
}

代码示例来源:origin: HotelsDotCom/styx

@Test
public void createsAResponseWithDefaultValues() {
  HttpResponse response = HttpResponse.response().build();
  assertThat(response.version(), is(HTTP_1_1));
  assertThat(response.cookies(), is(emptyIterable()));
  assertThat(response.headers(), is(emptyIterable()));
  assertThat(response.body().length, is(0));
}

代码示例来源:origin: HotelsDotCom/styx

@Test
public void createsANonCacheableResponse() {
  assertThat(HttpResponse.response().disableCaching().build().headers(), is(isNotCacheable()));
}

代码示例来源:origin: HotelsDotCom/styx

/**
 * Creates a new {@link Builder} object from a response code and a content stream.
 * <p>
 * Builder's response status line parameters and the HTTP headers are populated from
 * the given {@code response} object, but the content stream is set to {@code ByteStream}.
 *
 * @param response      a full response for which the builder is based on
 * @param byteStream a content byte stream
 */
public Builder(HttpResponse response, ByteStream byteStream) {
  this.status = statusWithCode(response.status().code());
  this.version = httpVersion(response.version().toString());
  this.headers = response.headers().newBuilder();
  this.body = requireNonNull(byteStream);
}

代码示例来源:origin: com.hotels.styx/styx-common

private static Info information(HttpResponse response, boolean longFormatEnabled) {
  Info info = new Info()
      .add("status", response.status());
  if (longFormatEnabled) {
    info.add("headers", response.headers())
        .add("cookies", response.cookies());
  }
  return info;
}

代码示例来源:origin: HotelsDotCom/styx

@Test
public void createsResponseWithMinimalInformation() {
  HttpResponse response = HttpResponse.response()
      .status(BAD_GATEWAY)
      .version(HTTP_1_1)
      .build();
  assertThat(response.status(), is(BAD_GATEWAY));
  assertThat(response.version(), is(HTTP_1_1));
  assertThat(response.cookies(), is(emptyIterable()));
  assertThat(response.headers(), is(emptyIterable()));
  assertThat(response.body().length, is(0));
}

代码示例来源:origin: HotelsDotCom/styx

@Test
public void canRemoveAHeader() {
  Object headerValue = "b";
  HttpResponse response = HttpResponse.response()
      .header("a", headerValue)
      .addHeader("c", headerValue)
      .build();
  HttpResponse shouldRemoveHeader = response.newBuilder()
      .removeHeader("c")
      .build();
  assertThat(shouldRemoveHeader.headers(), contains(header("a", "b")));
}

代码示例来源:origin: HotelsDotCom/styx

@Test
public void encodesToFullHttpResponse() {
  LiveHttpResponse response = response(CREATED)
      .version(HTTP_1_0)
      .header("HeaderName", "HeaderValue")
      .cookies(responseCookie("CookieName", "CookieValue").build())
      .body(new ByteStream(Flux.just("foo", "bar").map(it -> new Buffer(copiedBuffer(it, UTF_8)))))
      .build();
  HttpResponse full = Mono.from(response.aggregate(0x1000)).block();
  assertThat(full.status(), is(CREATED));
  assertThat(full.version(), is(HTTP_1_0));
  assertThat(full.headers(), containsInAnyOrder(header("HeaderName", "HeaderValue"), header("Set-Cookie", "CookieName=CookieValue")));
  assertThat(full.cookies(), contains(responseCookie("CookieName", "CookieValue").build()));
  assertThat(full.body(), is(bytes("foobar")));
}

相关文章