Tabnine Logo
LiveHttpResponse
Code IndexAdd Tabnine to your IDE (free)

How to use
LiveHttpResponse
in
com.hotels.styx.api

Best Java code snippets using com.hotels.styx.api.LiveHttpResponse (Showing top 20 results out of 315)

origin: HotelsDotCom/styx

/**
 * Creates a new {@link Builder} object from an existing {@link LiveHttpResponse} object.
 * Similar to {@link this.newBuilder} method.
 *
 * @param response a response object for which the builder is based on
 */
public Builder(LiveHttpResponse response) {
  this.status = response.status();
  this.version = response.version();
  this.headers = response.headers().newBuilder();
  this.body = response.body();
}
origin: HotelsDotCom/styx

public static HttpResponse waitForResponse(Observable<LiveHttpResponse> responseObs) {
  return responseObs
      .flatMap(response -> toObservable(response.aggregate(120*1024)))
      .toBlocking()
      .single();
}
origin: HotelsDotCom/styx

private static LiveHttpResponse disableCaching(LiveHttpResponse response) {
  return response.newBuilder()
      .disableCaching()
      .build();
}
origin: HotelsDotCom/styx

/**
 * Creates a new {@link Builder} object from a response code and a content byte array.
 *
 * @param response a streaming HTTP response instance
 * @param body a HTTP message body
 */
public Builder(LiveHttpResponse response, byte[] body) {
  this.status = response.status();
  this.version = response.version();
  this.headers = response.headers().newBuilder();
  this.body = body;
}
origin: HotelsDotCom/styx

private LiveHttpResponse removeRedundantContentLengthHeader(LiveHttpResponse response) {
  if (contentValidation && response.contentLength().isPresent() && response.chunked()) {
    return response.newBuilder()
        .removeHeader(CONTENT_LENGTH)
        .build();
  }
  return response;
}
origin: HotelsDotCom/styx

  @Override
  protected boolean matchesSafely(LiveHttpResponse response) {
    return response.status() == status;
  }
}
origin: HotelsDotCom/styx

@Test
public void convertsToStreamingHttpResponse() throws Exception {
  HttpResponse response = response(CREATED)
      .version(HTTP_1_1)
      .header("HeaderName", "HeaderValue")
      .cookies(responseCookie("CookieName", "CookieValue").build())
      .body("message content", UTF_8)
      .build();
  LiveHttpResponse streaming = response.stream();
  assertThat(streaming.version(), is(HTTP_1_1));
  assertThat(streaming.status(), is(CREATED));
  assertThat(streaming.headers(), containsInAnyOrder(
      header("Content-Length", "15"),
      header("HeaderName", "HeaderValue"),
      header("Set-Cookie", "CookieName=CookieValue")
  ));
  assertThat(streaming.cookies(), contains(responseCookie("CookieName", "CookieValue").build()));
  StepVerifier.create(streaming.aggregate(0x100000).map(it -> it.bodyAs(UTF_8)))
      .expectNext("message content")
      .verifyComplete();
}
origin: HotelsDotCom/styx

private static LiveHttpResponse.Builder response() {
  return LiveHttpResponse.response();
}
origin: HotelsDotCom/styx

private static Info information(LiveHttpResponse response, boolean longFormatEnabled) {
  Info info = new Info().add("status", response.status());
  if (longFormatEnabled) {
    info.add("headers", response.headers());
  }
  return info;
}
origin: HotelsDotCom/styx

@Test
public void transformsStatus() {
  LiveHttpResponse response = response(OK).build()
      .newBuilder()
      .status(MOVED_PERMANENTLY)
      .build();
  assertEquals(response.status(), MOVED_PERMANENTLY);
}
origin: HotelsDotCom/styx

@Test
public void transformerRemovesCookiesWithList() {
  LiveHttpResponse response = response()
      .addCookies(ImmutableList.of(responseCookie("x", "y").build()))
      .build()
      .newBuilder()
      .removeCookies(ImmutableList.of("x"))
      .build();
  assertEquals(response.cookie("x"), Optional.empty());
}
origin: HotelsDotCom/styx

@Test
public void shouldNotFailToRemoveNonExistentContentLength() {
  LiveHttpResponse response = response().build();
  LiveHttpResponse chunkedResponse = response.newBuilder().setChunked().build();
  assertThat(chunkedResponse.chunked(), is(true));
  assertThat(chunkedResponse.header(CONTENT_LENGTH).isPresent(), is(false));
}
origin: HotelsDotCom/styx

@Test
public void transformsBody() throws ExecutionException, InterruptedException {
  Buffer buffer = new Buffer("I'm going to get removed.", UTF_8);
  LiveHttpResponse response = response(NO_CONTENT)
      .body(new ByteStream(Flux.just(buffer)))
      .build();
  HttpResponse fullResponse = Mono.from(response.newBuilder()
      .body(ByteStream::drop)
      .build()
      .aggregate(1000)).block();
  assertThat(fullResponse.body().length, is(0));
  assertThat(buffer.delegate().refCnt(), is(0));
}
origin: HotelsDotCom/styx

@Test
public void transformerAddsHeaders() {
  LiveHttpResponse response = response().build()
      .newBuilder()
      .addHeader("X-Styx-ID", "y")
      .build();
  assertEquals(response.header("X-Styx-ID"), Optional.of("y"));
}
origin: HotelsDotCom/styx

private static CharSequence viaHeader(LiveHttpResponse httpMessage) {
  CharSequence styxViaEntry = styxViaEntry(httpMessage.version());
  return httpMessage.headers().get(VIA)
      .map(viaHeader -> !isNullOrEmpty(viaHeader) ? viaHeader + ", " + styxViaEntry : styxViaEntry)
      .orElse(styxViaEntry);
}
origin: HotelsDotCom/styx

private LiveHttpResponse exceptionToResponse(Throwable exception, LiveHttpRequest request) {
  HttpResponseStatus status = status(exception instanceof PluginException
      ? exception.getCause()
      : exception);
  String message = status.code() >= 500 ? "Site temporarily unavailable." : status.description();
  return responseEnhancer.enhance(
      LiveHttpResponse
          .response(status)
          .body(new ByteStream(Flux.just(new Buffer(message, UTF_8))))
          .build()
          .newBuilder(), request)
      .header(CONTENT_LENGTH, message.getBytes(UTF_8).length)
      .build();
}
origin: HotelsDotCom/styx

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

@Test
public void toFullResponseReleasesOriginalRefCountedBuffers() throws ExecutionException, InterruptedException {
  Buffer content = new Buffer(Unpooled.copiedBuffer("original", UTF_8));
  LiveHttpResponse original = LiveHttpResponse.response(OK)
      .body(new ByteStream(Flux.just(content)))
      .build();
  StepVerifier.create(original.aggregate(100))
      .expectNextCount(1)
      .then(() -> assertThat(content.delegate().refCnt(), is(0)))
      .verifyComplete();
}
origin: HotelsDotCom/styx

@Test
public void newCookiesWithDuplicateNamesOverridePreviousOnes() {
  LiveHttpResponse r1 = response()
      .cookies(responseCookie("y", "y1").build())
      .build();
  LiveHttpResponse r2 = r1.newBuilder().addCookies(
      responseCookie("y", "y2").build())
      .build();
  assertThat(r2.cookies(), containsInAnyOrder(responseCookie("y", "y2").build()));
}
origin: HotelsDotCom/styx

@Test
public void firesWhenContentCancelled() {
  EmitterProcessor<Buffer> contentPublisher = EmitterProcessor.create();
  Flux<LiveHttpResponse> listener = ResponseEventListener.from(
      Flux.just(response(OK)
          .body(new ByteStream(contentPublisher))
          .build()))
      .whenCancelled(() -> cancelled.set(true))
      .apply();
  StepVerifier.create(listener)
      .consumeNextWith(response ->
          StepVerifier.create(response.body())
              .then(() -> assertFalse(cancelled.get()))
              .thenCancel()
              .verify())
      .verifyComplete();
  assertTrue(cancelled.get());
}
com.hotels.styx.apiLiveHttpResponse

Javadoc

An HTTP response object with a byte stream body.

An LiveHttpResponse is used in HttpInterceptor where each content chunk must be processed as they arrive. It is also useful for dealing with very large content sizes, and in situations where content size is not known upfront.

An LiveHttpResponse object is immutable with respect to the response attributes and HTTP headers. Once an instance is created, they cannot change.

An LiveHttpResponse body is a byte buffer stream that can be consumed as sequence of asynchronous events. Once consumed, the stream is exhausted and can not be reused. Conceptually each LiveHttpResponse object has an associated producer object that publishes data to the stream. For example, a Styx Server implements a content producer for HttpInterceptorextensions. The producer receives data chunks from a network socket and publishes them to an appropriate content stream.

HTTP responses are created via Builder object, which can be created with static helper methods:

  • response()
  • response(HttpResponseStatus)
  • response(HttpResponseStatus, Eventual)

A builder can also be created with one of the Builder constructors. A special method newBuilder creates a prepopulated Builderfrom the current response object. It is useful for transforming a response to another one my modifying one or more of its attributes.

Most used methods

  • status
  • aggregate
    Aggregates content stream and converts this response to a HttpResponse. Returns a Eventual that even
  • headers
  • newBuilder
    Return a new LiveHttpResponse.Builder that will inherit properties from this response. This allows a
  • response
    Creates an HTTP response builder with a given status and body.
  • body
  • version
  • chunked
  • consume
  • contentLength
  • cookies
    Decodes "Set-Cookie" header values and returns them as set of ResponseCookie objects.
  • header
  • cookies,
  • header,
  • <init>,
  • cookie,
  • decodeAndRelease,
  • isRedirect

Popular in Java

  • Finding current android device location
  • getResourceAsStream (ClassLoader)
  • getApplicationContext (Context)
  • requestLocationUpdates (LocationManager)
  • String (java.lang)
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • StringTokenizer (java.util)
    Breaks a string into tokens; new code should probably use String#split.> // Legacy code: StringTo
  • Timer (java.util)
    Timers schedule one-shot or recurring TimerTask for execution. Prefer java.util.concurrent.Scheduled
  • JTable (javax.swing)
  • Option (scala)
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now