congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
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

  • Making http post requests using okhttp
  • compareTo (BigDecimal)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • Runner (org.openjdk.jmh.runner)
  • Top plugins for WebStorm
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