congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
RawHttpResponse.getBody
Code IndexAdd Tabnine to your IDE (free)

How to use
getBody
method
in
rawhttp.core.RawHttpResponse

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

origin: renatoathaydes/rawhttp

@Override
public Optional<EagerBodyReader> getBody() {
  Optional<? extends BodyReader> body = super.getBody();
  return body.map(b -> (EagerBodyReader) b);
}
origin: com.athaydes.rawhttp/rawhttp-core

@Override
public Optional<EagerBodyReader> getBody() {
  Optional<? extends BodyReader> body = super.getBody();
  return body.map(b -> (EagerBodyReader) b);
}
origin: renatoathaydes/rawhttp

private static void closeBodyOf(RawHttpResponse<?> response) {
  if (response != null) {
    response.getBody().ifPresent(b -> {
      try {
        b.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    });
  }
}
origin: com.athaydes.rawhttp/rawhttp-core

private static void closeBodyOf(RawHttpResponse<?> response) {
  if (response != null) {
    response.getBody().ifPresent(b -> {
      try {
        b.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    });
  }
}
origin: com.athaydes.rawhttp/rawhttp-core

/**
 * Create a copy of this HTTP response, replacing its statusLine with the provided one.
 *
 * @param statusLine to replace
 * @return copy of this HTTP message with the provided statusLine
 */
public RawHttpResponse<Response> withStatusLine(StatusLine statusLine) {
  return new RawHttpResponse<>(libResponse, request, statusLine,
      getHeaders(), getBody().orElse(null));
}
origin: renatoathaydes/rawhttp

/**
 * Create a copy of this HTTP response, replacing its statusLine with the provided one.
 *
 * @param statusLine to replace
 * @return copy of this HTTP message with the provided statusLine
 */
public RawHttpResponse<Response> withStatusLine(StatusLine statusLine) {
  return new RawHttpResponse<>(libResponse, request, statusLine,
      getHeaders(), getBody().orElse(null));
}
origin: renatoathaydes/rawhttp

@Override
public void logRequest(RawHttpRequest request, RawHttpResponse<?> response) {
  executor.submit(() -> {
    if (request.getSenderAddress().isPresent()) {
      InetAddress senderAddress = request.getSenderAddress().get();
      System.out.print(senderAddress.getHostAddress() + " ");
    }
    Long bytes = response.getBody()
        .map(b -> b.getLengthIfKnown().orElse(-1L))
        .orElse(-1L);
    System.out.println("[" + LocalDateTime.now().format(dateFormat) + "] \"" +
        request.getStartLine() + "\" " + response.getStatusCode() +
        " " + bytes);
  });
}
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.
 *
 * @param keepAlive whether to keep the connection alive. If false, the {@link BodyReader}
 *                  associated with this response is closed after by the time this method returns.
 * @return this response, after eagerly downloading all of its contents.
 * @throws IOException if an error occurs while reading this response
 */
public EagerHttpResponse<Response> eagerly(boolean keepAlive) throws IOException {
  try {
    return EagerHttpResponse.from(this);
  } finally {
    if (!keepAlive) {
      getBody().ifPresent(b -> {
        try {
          b.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      });
    }
  }
}
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.
 *
 * @param keepAlive whether to keep the connection alive. If false, the {@link BodyReader}
 *                  associated with this response is closed after by the time this method returns.
 * @return this response, after eagerly downloading all of its contents.
 * @throws IOException if an error occurs while reading this response
 */
public EagerHttpResponse<Response> eagerly(boolean keepAlive) throws IOException {
  try {
    return EagerHttpResponse.from(this);
  } finally {
    if (!keepAlive) {
      getBody().ifPresent(b -> {
        try {
          b.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      });
    }
  }
}
origin: com.athaydes.rawhttp/rawhttp-core

@Override
public RawHttpResponse<Response> withHeaders(RawHttpHeaders headers, boolean append) {
  return new RawHttpResponse<>(libResponse, request, statusLine,
      append ? getHeaders().and(headers) : headers.and(getHeaders()),
      getBody().orElse(null));
}
origin: renatoathaydes/rawhttp

@Override
public RawHttpResponse<Response> withHeaders(RawHttpHeaders headers, boolean append) {
  return new RawHttpResponse<>(libResponse, request, statusLine,
      append ? getHeaders().and(headers) : headers.and(getHeaders()),
      getBody().orElse(null));
}
origin: com.athaydes.rawhttp/rawhttp-core

@Nullable EagerBodyReader bodyReader = response.getBody().isPresent() ?
    response.getBody().get().eager() :
    null;
origin: renatoathaydes/rawhttp

@Nullable EagerBodyReader bodyReader = response.getBody().isPresent() ?
    response.getBody().get().eager() :
    null;
origin: renatoathaydes/rawhttp

RawHttpResponse<Void> response = client.send(request);
if (options.printBodyOnly) {
  if (response.getBody().isPresent()) {
    response.getBody().get().writeTo(System.out);
origin: renatoathaydes/rawhttp

@Test
public void sendRawRequest() throws IOException {
  RawHttp http = new RawHttp();
  RawHttpRequest request = http.parseRequest(
      "GET / HTTP/1.1\r\n" +
          "Host: headers.jsontest.com\r\n" +
          "User-Agent: RawHTTP\r\n" +
          "Accept: application/json");
  Socket socket = new Socket("headers.jsontest.com", 80);
  request.writeTo(socket.getOutputStream());
  // get the response
  RawHttpResponse<?> response = http.parseResponse(socket.getInputStream());
  assertEquals(200, response.getStatusCode());
  assertTrue(response.getBody().isPresent());
  String textBody = response.getBody().get().decodeBodyToString(UTF_8);
  assertTrue(textBody.contains("\"User-Agent\": \"RawHTTP\""));
}
origin: renatoathaydes/rawhttp

InputStream responseStream = response.getBody().map(b -> b.isChunked() ? b.asRawStream() : null)
    .orElseThrow(() ->
        new IllegalStateException("HTTP response does not contain a chunked body"));
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

@Test
public void requestWithTcpRawHttpClient() throws IOException {
  TcpRawHttpClient client = new TcpRawHttpClient();
  RawHttp http = new RawHttp();
  RawHttpRequest request = http.parseRequest(
      "GET / HTTP/1.1\r\n" +
          "Host: headers.jsontest.com\r\n" +
          "User-Agent: RawHTTP\r\n" +
          "Accept: application/json");
  RawHttpResponse<?> response = client.send(request);
  assertEquals(200, response.getStatusCode());
  assertTrue(response.getBody().isPresent());
  String textBody = response.getBody().get().decodeBodyToString(UTF_8);
  assertTrue(textBody.contains("\"User-Agent\": \"RawHTTP\""));
  client.close();
}
origin: renatoathaydes/rawhttp

assertTrue(response.getBody().isPresent());
String textBody = response.getBody().get().decodeBodyToString(UTF_8);
assertTrue(textBody.contains(jsonBody.replaceAll(" ", "")));
origin: renatoathaydes/rawhttp

assertTrue(response.getBody().isPresent());
String textBody = response.getBody().get().decodeBodyToString(UTF_8);
assertTrue(textBody.contains("\"userId\": 1"));
rawhttp.coreRawHttpResponsegetBody

Popular methods of RawHttpResponse

  • writeTo
  • <init>
  • eagerly
    Ensure that this response is read eagerly, downloading the full body if necessary. The returned obje
  • getHeaders
  • getStatusCode
  • withHeaders
  • getLibResponse
  • getRequest
  • getStartLine
  • withBody

Popular in Java

  • Finding current android device location
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • onCreateOptionsMenu (Activity)
  • startActivity (Activity)
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
  • Sublime Text for Python
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