Tabnine Logo
HttpRequest$Builder.build
Code IndexAdd Tabnine to your IDE (free)

How to use
build
method
in
com.hotels.styx.api.HttpRequest$Builder

Best Java code snippets using com.hotels.styx.api.HttpRequest$Builder.build (Showing top 20 results out of 315)

origin: HotelsDotCom/styx

@Test
public void contentFromStringOnlySetsContentLength() {
  HttpRequest request = HttpRequest.get("/")
      .body("Response content.", UTF_16)
      .build();
  assertThat(request.body(), is("Response content.".getBytes(UTF_16)));
  assertThat(request.header("Content-Length"), is(Optional.of("36")));
}
origin: HotelsDotCom/styx

@Test
public void extractsMultipleQueryParameterValues() {
  HttpRequest req = get("http://host.com:8080/path?fish=cod&fruit=orange&fish=smørflyndre").build();
  assertThat(req.queryParams("fish"), contains("cod", "smørflyndre"));
}
origin: HotelsDotCom/styx

@Test
public void returnsEmptyListWhenThereIsNoSuchParameter() {
  HttpRequest req = get("http://host.com:8080/path?poisson=cabillaud").build();
  assertThat(req.queryParams("fish"), is(emptyIterable()));
  assertThat(req.queryParam("fish"), isAbsent());
}
origin: HotelsDotCom/styx

@Test
public void decodesQueryParamsContainingEncodedEquals() {
  HttpRequest request = get("http://example.com/?foo=a%2Bb%3Dc")
      .build();
  assertThat(request.queryParam("foo"), isValue("a+b=c"));
}
origin: HotelsDotCom/styx

@Test
public void decodesQueryParams() {
  HttpRequest request = get("http://example.com/?foo=bar").build();
  assertThat(request.queryParam("foo"), isValue("bar"));
}
origin: HotelsDotCom/styx

@Test
public void alwaysReturnsEmptyListWhenThereIsNoQueryString() {
  HttpRequest req = get("http://host.com:8080/path").build();
  assertThat(req.queryParams("fish"), is(emptyIterable()));
  assertThat(req.queryParam("fish"), isAbsent());
}
origin: HotelsDotCom/styx

@Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "Charset is not provided.")
public void contentFromStringThrowsNPEWhenCharsetIsNull() {
  HttpRequest.get("/")
      .body("Response content.", null, false)
      .build();
}
origin: HotelsDotCom/styx

@Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "Charset is not provided.")
public void contentFromStringOnlyThrowsNPEWhenCharsetIsNull() {
  HttpRequest.get("/")
      .body("Response content.", null)
      .build();
}
origin: HotelsDotCom/styx

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

@Test
public void addsCookiesToExistingCookies() {
  HttpRequest request = HttpRequest.get("/")
      .addCookies(requestCookie("z", "z1"))
      .addCookies(requestCookie("x", "x1"), requestCookie("y", "y1"))
      .build();
  assertThat(request.cookies(), containsInAnyOrder(requestCookie("x", "x1"), requestCookie("y", "y1"), requestCookie("z", "z1")));
}
origin: HotelsDotCom/styx

@Test
public void setsHostHeaderFromAuthorityIfSet() {
  HttpRequest request = get("http://www.hotels.com").build();
  assertThat(request.header(HOST), isValue("www.hotels.com"));
}
origin: HotelsDotCom/styx

@Test
public void canExtractCookies() {
  HttpRequest request = get("/")
      .cookies(
          requestCookie("cookie1", "foo"),
          requestCookie("cookie3", "baz"),
          requestCookie("cookie2", "bar"))
      .build();
  assertThat(request.cookie("cookie1"), isValue(requestCookie("cookie1", "foo")));
  assertThat(request.cookie("cookie2"), isValue(requestCookie("cookie2", "bar")));
  assertThat(request.cookie("cookie3"), isValue(requestCookie("cookie3", "baz")));
}
origin: HotelsDotCom/styx

@Test
public void extractsSingleQueryParameter() {
  HttpRequest req = get("http://host.com:8080/path?fish=cod&fruit=orange")
      .build();
  assertThat(req.queryParam("fish"), isValue("cod"));
}
origin: HotelsDotCom/styx

@Test
public void canUseBuilderToSetRequestProperties() {
  HttpRequest request = patch("https://hotels.com")
      .version(HTTP_1_1)
      .id("id")
      .header("headerName", "a")
      .cookies(requestCookie("cfoo", "bar"))
      .build();
  assertThat(request.toString(), is("HttpRequest{version=HTTP/1.1, method=PATCH, uri=https://hotels.com, " +
      "headers=[headerName=a, Cookie=cfoo=bar, Host=hotels.com], id=id}"));
  assertThat(request.headers("headerName"), is(singletonList("a")));
}
origin: com.hotels.styx/styx-client

private static HttpRequest addUserAgent(HttpRequest request, String userAgent) {
  return request.newBuilder()
      .addHeader(USER_AGENT, userAgent)
      .build();
}
origin: HotelsDotCom/styx

public static MetricsSnapshot downloadFrom(String host, int port) throws IOException {
  HttpClient client = new StyxHttpClient.Builder().build();
  HttpResponse response = await(client.sendRequest(get(format("http://%s:%d/admin/metrics", host, port)).build()));
  return new MetricsSnapshot(decodeToMap(response.bodyAs(UTF_8)));
}
origin: HotelsDotCom/styx

@Test(expectedExceptions = IllegalArgumentException.class)
public void rejectsInvalidContentLength() {
  get("/foo")
      .addHeader(CONTENT_LENGTH, "foo")
      .build();
}
origin: HotelsDotCom/styx

@Test
public void createsRequestBuilderFromRequest() {
  HttpRequest originalRequest = get("/home")
      .cookies(requestCookie("fred", "blogs"))
      .header("some", "header")
      .build();
  HttpRequest clonedRequest = originalRequest.newBuilder().build();
  assertThat(clonedRequest.method(), is(originalRequest.method()));
  assertThat(clonedRequest.url(), is(originalRequest.url()));
  assertThat(clonedRequest.headers().toString(), is(originalRequest.headers().toString()));
  assertThat(clonedRequest.body(), is(originalRequest.body()));
}
origin: HotelsDotCom/styx

@Test
public void transformedBodyIsNewCopy() {
  HttpRequest request = get("/foo")
      .body("Original body", UTF_8)
      .build();
  HttpRequest newRequest = request.newBuilder()
      .body("New body", UTF_8)
      .build();
  assertThat(request.bodyAs(UTF_8), is("Original body"));
  assertThat(newRequest.bodyAs(UTF_8), is("New body"));
}
origin: com.hotels.styx/styx-client

private HttpRequest newHealthCheckRequestFor(Origin origin) {
  return get(healthCheckUri)
      .header(HOST, origin.hostAsString())
      .build();
}
com.hotels.styx.apiHttpRequest$Builderbuild

Javadoc

Builds a new full request based on the settings configured in this builder. If validate is set to true:
  • the host header will be set if absent
  • an exception will be thrown if the content length is not an integer, or more than one content length exists
  • an exception will be thrown if the request method is not a valid HTTP method

Popular methods of HttpRequest$Builder

  • header
  • <init>
    Creates a builder with an HTTP method and URI.
  • addCookies
    Adds cookies into the "Cookie" header. If the name matches an already existing cookie, the value wil
  • addHeader
  • body
    Sets the request body. This method encodes the content to a byte array provided, and sets the Conten
  • cookies
    Sets the cookies on this request by overwriting the value of the "Cookie" header.
  • removeCookies
    Removes all cookies matching one of the supplied names by overwriting the value of the "Cookie" head
  • url
    Sets the request fully qualified url.
  • version
  • addCookie
    Adds a new cookie to the Cookie header with the specified name and value. Creates the Cookie header
  • clientAddress
    Sets the client IP address.
  • enableKeepAlive
    Enables Keep-Alive.
  • clientAddress,
  • enableKeepAlive,
  • ensureContentLengthIsValid,
  • ensureMethodIsValid,
  • get,
  • headers,
  • id,
  • isMethodValid,
  • isNonNegativeInteger

Popular in Java

  • Updating database using SQL prepared statement
  • addToBackStack (FragmentTransaction)
  • getSupportFragmentManager (FragmentActivity)
  • onRequestPermissionsResult (Fragment)
  • Kernel (java.awt.image)
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • Timer (java.util)
    Timers schedule one-shot or recurring TimerTask for execution. Prefer java.util.concurrent.Scheduled
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • From CI to AI: The AI layer in your organization
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