Codota Logo
RawHttp.parseResponse
Code IndexAdd Codota to your IDE (free)

How to use
parseResponse
method
in
rawhttp.core.RawHttp

Best Java code snippets using rawhttp.core.RawHttp.parseResponse (Showing top 16 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
FileOutputStream f =
  • Codota IconFile file;new FileOutputStream(file)
  • Codota IconString name;new FileOutputStream(name)
  • Codota IconFile file;new FileOutputStream(file, true)
  • Smart code suggestions by Codota
}
origin: renatoathaydes/rawhttp

/**
 * Parses the HTTP response produced by the given stream.
 *
 * @param inputStream producing a HTTP response
 * @return a parsed HTTP response object
 * @throws InvalidHttpResponse if the response is invalid
 * @throws IOException         if a problem occurs accessing the stream
 */
public final RawHttpResponse<Void> parseResponse(InputStream inputStream) throws IOException {
  return parseResponse(inputStream, null);
}
origin: com.athaydes.rawhttp/rawhttp-core

/**
 * Parses the HTTP response produced by the given stream.
 *
 * @param inputStream producing a HTTP response
 * @return a parsed HTTP response object
 * @throws InvalidHttpResponse if the response is invalid
 * @throws IOException         if a problem occurs accessing the stream
 */
public final RawHttpResponse<Void> parseResponse(InputStream inputStream) throws IOException {
  return parseResponse(inputStream, null);
}
origin: com.athaydes.rawhttp/rawhttp-core

/**
 * Parses the given HTTP response.
 *
 * @param response in text form
 * @return a parsed HTTP response object
 * @throws InvalidHttpResponse if the response is invalid
 */
public final RawHttpResponse<Void> parseResponse(String response) {
  try {
    return parseResponse(
        new ByteArrayInputStream(response.getBytes(UTF_8)),
        null);
  } catch (IOException e) {
    // IOException should be impossible
    throw new RuntimeException(e);
  }
}
origin: renatoathaydes/rawhttp

/**
 * Create a new instance of {@link RawHttpDuplex} that uses the given options.
 * <p>
 * This is the most general constructor, as {@link RawHttpDuplexOptions} can provide all options other constructors
 * accept.
 *
 * @param options to use for this instance
 */
public RawHttpDuplex(RawHttpDuplexOptions options) {
  this.okResponse = new RawHttp().parseResponse("200 OK");
  this.options = options;
}
origin: renatoathaydes/rawhttp

/**
 * Parses the given HTTP response.
 *
 * @param response in text form
 * @return a parsed HTTP response object
 * @throws InvalidHttpResponse if the response is invalid
 */
public final RawHttpResponse<Void> parseResponse(String response) {
  try {
    return parseResponse(
        new ByteArrayInputStream(response.getBytes(UTF_8)),
        null);
  } catch (IOException e) {
    // IOException should be impossible
    throw new RuntimeException(e);
  }
}
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> send(RawHttpRequest request) throws IOException {
  Socket socket;
  try {
    socket = options.getSocket(request.getUri());
  } catch (RuntimeException e) {
    Throwable cause = e.getCause();
    if (cause instanceof IOException) {
      throw (IOException) cause;
    }
    throw e;
  }
  OutputStream outputStream = socket.getOutputStream();
  options.getExecutorService().submit(() -> {
    try {
      request.writeTo(outputStream);
    } catch (IOException e) {
      e.printStackTrace();
    }
  });
  return options.onResponse(socket, request.getUri(),
      rawHttp.parseResponse(socket.getInputStream()));
}
origin: renatoathaydes/rawhttp

@Override
public RawHttpResponse<Void> send(RawHttpRequest request) throws IOException {
  Socket socket;
  try {
    socket = options.getSocket(request.getUri());
  } catch (RuntimeException e) {
    Throwable cause = e.getCause();
    if (cause instanceof IOException) {
      throw (IOException) cause;
    }
    throw e;
  }
  OutputStream outputStream = socket.getOutputStream();
  options.getExecutorService().submit(() -> {
    try {
      request.writeTo(outputStream);
    } catch (IOException e) {
      e.printStackTrace();
    }
  });
  return options.onResponse(socket, request.getUri(),
      rawHttp.parseResponse(socket.getInputStream()));
}
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

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

System.out.println("REQUEST:\n" + request);
if (request.getUri().getPath().equals("/saysomething")) {
  http.parseResponse("HTTP/1.1 200 OK\n" +
      "Content-Type: text/plain\n" +
      "Content-Length: 9\n" +
      "something").writeTo(client.getOutputStream());
} else {
  http.parseResponse("HTTP/1.1 404 Not Found\n" +
      "Content-Type: text/plain\n" +
      "Content-Length: 0\n" +
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 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

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

Javadoc

Parses the HTTP response contained in the given file.

Popular methods of RawHttp

  • <init>
    Create a configured instance of RawHttp.
  • parseRequest
    Parses the given HTTP request.
  • getFramedBody
    Get the framed body of a HTTP message with the given start-line and headers. This method assumes th
  • createBodyReader
  • requestHasBody
    Determines whether a request with the given headers should have a body.
  • responseHasBody
    Determines whether a response with the given status-line should have a body. If provided, the reques
  • startsWith
  • verifyHost
  • waitForPortToBeTaken
    Wait for the given port to be taken before proceeding. This is useful for waiting for a server to cl

Popular in Java

  • Running tasks concurrently on multiple threads
  • scheduleAtFixedRate (Timer)
  • putExtra (Intent)
  • setRequestProperty (URLConnection)
    Sets the general request property. If a property with the key already exists, overwrite its value wi
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now