congrats Icon
New! Announcing our next generation AI code completions
Read here
Tabnine Logo
RawHttpResponse.eagerly
Code IndexAdd Tabnine to your IDE (free)

How to use
eagerly
method
in
rawhttp.core.RawHttpResponse

Best Java code snippets using rawhttp.core.RawHttpResponse.eagerly (Showing top 13 results out of 315)

origin: com.athaydes.rawhttp/rawhttp-core

/**
 * Ensure that this response is read eagerly, downloading the full body if necessary.
 * <p>
 * The returned object can be safely passed around after the connection used to receive
 * this response has been closed.
 * <p>
 * The connection or stream used to download the response is NOT closed after a call to
 * this method. Use {@link #eagerly(boolean)} if a different behaviour is required.
 *
 * @return this response, after eagerly downloading all of its contents.
 * @throws IOException if an error occurs while reading this response
 */
public EagerHttpResponse<Response> eagerly() throws IOException {
  return eagerly(true);
}
origin: renatoathaydes/rawhttp

/**
 * Ensure that this response is read eagerly, downloading the full body if necessary.
 * <p>
 * The returned object can be safely passed around after the connection used to receive
 * this response has been closed.
 * <p>
 * The connection or stream used to download the response is NOT closed after a call to
 * this method. Use {@link #eagerly(boolean)} if a different behaviour is required.
 *
 * @return this response, after eagerly downloading all of its contents.
 * @throws IOException if an error occurs while reading this response
 */
public EagerHttpResponse<Response> eagerly() throws IOException {
  return eagerly(true);
}
origin: com.athaydes.rawhttp/rawhttp-core

/**
 * Parses the HTTP response contained in the given file.
 *
 * @param file containing a HTTP response
 * @return a parsed HTTP response object
 * @throws InvalidHttpResponse if the response is invalid
 * @throws IOException         if a problem occurs reading the file
 */
public final RawHttpResponse<Void> parseResponse(File file) throws IOException {
  try (InputStream stream = Files.newInputStream(file.toPath())) {
    return parseResponse(stream, null).eagerly();
  }
}
origin: renatoathaydes/rawhttp

/**
 * Parses the HTTP response contained in the given file.
 *
 * @param file containing a HTTP response
 * @return a parsed HTTP response object
 * @throws InvalidHttpResponse if the response is invalid
 * @throws IOException         if a problem occurs reading the file
 */
public final RawHttpResponse<Void> parseResponse(File file) throws IOException {
  try (InputStream stream = Files.newInputStream(file.toPath())) {
    return parseResponse(stream, null).eagerly();
  }
}
origin: com.athaydes.rawhttp/rawhttp-core

@Override
public RawHttpResponse<Void> onResponse(Socket socket,
                    URI uri,
                    RawHttpResponse<Void> httpResponse) throws IOException {
  if (httpResponse.getHeaders()
      .getFirst("Connection")
      .orElse("")
      .equalsIgnoreCase("close") ||
      httpResponse.getStartLine().getHttpVersion().isOlderThan(HttpVersion.HTTP_1_1)) {
    socketByHost.remove(uri.getHost());
    // resolve the full response before closing the socket
    return httpResponse.eagerly(false);
  }
  return httpResponse;
}
origin: renatoathaydes/rawhttp

@Override
public RawHttpResponse<Void> onResponse(Socket socket,
                    URI uri,
                    RawHttpResponse<Void> httpResponse) throws IOException {
  if (httpResponse.getHeaders()
      .getFirst("Connection")
      .orElse("")
      .equalsIgnoreCase("close") ||
      httpResponse.getStartLine().getHttpVersion().isOlderThan(HttpVersion.HTTP_1_1)) {
    socketByHost.remove(uri.getHost());
    // resolve the full response before closing the socket
    return httpResponse.eagerly(false);
  }
  return httpResponse;
}
origin: renatoathaydes/rawhttp

@Test
public void goingRawWithoutFancyClient() throws IOException {
  RawHttp rawHttp = new RawHttp();
  RawHttpRequest request = rawHttp.parseRequest(String.format("GET localhost:%d/hello HTTP/1.0", PORT));
  Socket socket = new Socket("localhost", PORT);
  request.writeTo(socket.getOutputStream());
  EagerHttpResponse<?> response = rawHttp.parseResponse(socket.getInputStream()).eagerly();
  assertThat(response.getStatusCode(), is(200));
  assertThat(response.getBody().map(EagerBodyReader::toString)
      .orElseThrow(() -> new RuntimeException("No body")), equalTo("Hello"));
}
origin: renatoathaydes/rawhttp

@Test
public void frontPageExample() throws IOException {
  RawHttp rawHttp = new RawHttp();
  RawHttpRequest request = rawHttp.parseRequest(
      "GET /hello.txt HTTP/1.1\r\n" +
          "User-Agent: curl/7.16.3 libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3\r\n" +
          "Host: www.example.com\r\n" +
          "Accept-Language: en, mi");
  Socket socket = new Socket("www.example.com", 80);
  request.writeTo(socket.getOutputStream());
  EagerHttpResponse<?> response = rawHttp.parseResponse(socket.getInputStream()).eagerly();
  // call "eagerly()" in order to download the body
  System.out.println(response.eagerly());
  assertThat(response.getStatusCode(), equalTo(404));
  assertTrue(response.getBody().isPresent());
  File responseFile = Files.createTempFile("rawhttp", ".http").toFile();
  try (OutputStream out = Files.newOutputStream(responseFile.toPath())) {
    response.writeTo(out);
  }
  System.out.printf("Response parsed from file (%s):", responseFile);
  System.out.println(rawHttp.parseResponse(responseFile).eagerly());
}
origin: renatoathaydes/rawhttp

@Test
public void usingRawHttpWithHttpComponents() throws IOException {
  RawHttpClient<?> client = new RawHttpComponentsClient();
  RawHttpRequest request = new RawHttp().parseRequest(String.format("GET localhost:%d/hello HTTP/1.0", PORT));
  EagerHttpResponse<?> response = client.send(request).eagerly();
  assertThat(response.getStatusCode(), is(200));
  assertThat(response.getBody().map(EagerBodyReader::toString)
      .orElseThrow(() -> new RuntimeException("No body")), equalTo("Hello"));
}
origin: renatoathaydes/rawhttp

RawHttpResponse<?> response = http.parseResponse(socket.getInputStream()).eagerly();
System.out.println("RESPONSE:\n" + response);
assertEquals(200, response.getStatusCode());
origin: renatoathaydes/rawhttp

EagerHttpResponse<?> rawResponse = client.send(request).eagerly();
rawHttpStatusCode = rawResponse.getStatusCode();
rawHttpContentType = rawResponse.getHeaders().getFirst(HttpHeaders.CONTENT_TYPE).orElse("");
origin: renatoathaydes/rawhttp

@Test
public void useHttpServer() throws InterruptedException, IOException {
  RawHttpServer server = new TcpRawHttpServer(8086);
  RawHttp http = new RawHttp();
  server.start(request -> {
    System.out.println("Got Request:\n" + request);
    String body = "Hello RawHTTP!";
    String dateString = RFC_1123_DATE_TIME.format(ZonedDateTime.now(ZoneOffset.UTC));
    RawHttpResponse<?> response = http.parseResponse("HTTP/1.1 200 OK\r\n" +
        "Content-Type: plain/text\r\n" +
        "Content-Length: " + body.length() + "\r\n" +
        "Server: RawHTTP\r\n" +
        "Date: " + dateString + "\r\n" +
        "\r\n" +
        body);
    return Optional.of(response);
  });
  // wait for the socket get bound
  Thread.sleep(150L);
  RawHttpRequest request = http.parseRequest("GET /\r\nHost: localhost");
  Socket socket = new Socket(InetAddress.getLoopbackAddress(), 8086);
  request.writeTo(socket.getOutputStream());
  // get the response
  RawHttpResponse<?> response = http.parseResponse(socket.getInputStream()).eagerly();
  System.out.println("RESPONSE:\n" + response);
  assertEquals(200, response.getStatusCode());
  assertTrue(response.getBody().isPresent());
  assertEquals("Hello RawHTTP!", response.getBody().get().decodeBodyToString(UTF_8));
  server.stop();
}
origin: renatoathaydes/rawhttp

RawHttpResponse<?> response = http.parseResponse(socket.getInputStream()).eagerly();
System.out.println("RESPONSE:\n" + response);
rawhttp.coreRawHttpResponseeagerly

Javadoc

Ensure that this response is read eagerly, downloading the full body if necessary.

The returned object can be safely passed around after the connection used to receive this response has been closed.

The connection or stream used to download the response is NOT closed after a call to this method. Use #eagerly(boolean) if a different behaviour is required.

Popular methods of RawHttpResponse

  • getBody
  • writeTo
  • <init>
  • getHeaders
  • getStatusCode
  • withHeaders
  • getLibResponse
  • getRequest
  • getStartLine
  • withBody

Popular in Java

  • Reactive rest calls using spring rest template
  • onRequestPermissionsResult (Fragment)
  • getExternalFilesDir (Context)
  • setContentView (Activity)
  • Rectangle (java.awt)
    A Rectangle specifies an area in a coordinate space that is enclosed by the Rectangle object's top-
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • Semaphore (java.util.concurrent)
    A counting semaphore. Conceptually, a semaphore maintains a set of permits. Each #acquire blocks if
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • Top 17 Free Sublime Text Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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