congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
RawHttp.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
rawhttp.core.RawHttp
constructor

Best Java code snippets using rawhttp.core.RawHttp.<init> (Showing top 19 results out of 315)

origin: renatoathaydes/rawhttp

public RawHttpComponentsClient(CloseableHttpClient httpClient) {
  this(httpClient, new RawHttp());
}
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: com.athaydes.rawhttp/rawhttp-core

/**
 * Create a new {@link TcpRawHttpClient} using the given options, which can give a custom
 * socketProvider and onClose callback.
 * <p>
 * If no options are given, {@link DefaultOptions} is used.
 *
 * @param options configuration for this client
 */
public TcpRawHttpClient(@Nullable TcpRawHttpClientOptions options) {
  this(options == null ? new DefaultOptions() : options,
      new RawHttp(RawHttpOptions.newBuilder()
          .doNotAllowNewLineWithoutReturn()
          .build()));
}
origin: renatoathaydes/rawhttp

/**
 * Create a new {@link TcpRawHttpClient} using the given options, which can give a custom
 * socketProvider and onClose callback.
 * <p>
 * If no options are given, {@link DefaultOptions} is used.
 *
 * @param options configuration for this client
 */
public TcpRawHttpClient(@Nullable TcpRawHttpClientOptions options) {
  this(options == null ? new DefaultOptions() : options,
      new RawHttp(RawHttpOptions.newBuilder()
          .doNotAllowNewLineWithoutReturn()
          .build()));
}
origin: renatoathaydes/rawhttp

@Test(expected = FileNotFoundException.class)
public void replacingBodyWithFile() throws Throwable {
  RawHttp http = new RawHttp();
  RawHttpRequest request = http.parseRequest("POST http://example.com/hello");
  try {
    RawHttpRequest requestWithBody = request.withBody(
        new FileBody(new File("hello.request"), "text/plain"));
    System.out.println(requestWithBody.eagerly());
  } catch (RuntimeException e) {
    throw e.getCause();
  }
}
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 replacingBodyWithChunkedEncodedMessage() throws IOException {
  InputStream stream = new ByteArrayInputStream("Hello RawHTTTP".getBytes());
  int chunkSize = 4;
  RawHttp http = new RawHttp();
  RawHttpRequest request = http.parseRequest("POST http://example.com/hello");
  RawHttpRequest requestWithBody = request.withBody(
      new ChunkedBody(stream, "text/plain", chunkSize));
  System.out.println(requestWithBody.eagerly());
}
origin: renatoathaydes/rawhttp

@Test
public void replacingBodyWithBytes() throws IOException {
  byte[] bytes = "Hello RawHTTP".getBytes();
  RawHttp http = new RawHttp();
  RawHttpRequest request = http.parseRequest("POST http://example.com/hello");
  RawHttpRequest requestWithBody = request.withBody(
      new BytesBody(bytes, "text/plain"));
  System.out.println(requestWithBody.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

@Test
public void replacingBodyWithString() throws IOException {
  RawHttp http = new RawHttp();
  RawHttpRequest request = http.parseRequest("POST http://example.com/hello");
  RawHttpRequest requestWithBody = request.withBody(new StringBody("Hello RawHTTP", "text/plain"));
  System.out.println(requestWithBody.eagerly());
}
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 rudimentaryHttpServerCalledFromHttpComponentsClient() throws Exception {
  RawHttp http = new RawHttp();
  ServerSocket server = new ServerSocket(8084);
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

  throws IOException, InterruptedException {
ServerSocket serverSocket = new ServerSocket(8082);
RawHttp http = new RawHttp();
CountDownLatch latch = new CountDownLatch(1);
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

RawHttpRequest request = new RawHttp().parseRequest(
    "GET / HTTP/1.0\n" +
        "User-Agent: curl/7.16.3 libcurl/7.16.3 OpenSSL/0.9.7l zlib/1.2.3\n" +
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

@Test
public void sendRawPostRequest() throws IOException {
  String jsonBody = "{ \"hello\": true, \"raw_http\": \"2.0\" }";
  RawHttp http = new RawHttp();
  RawHttpRequest request = http.parseRequest(
      "POST /post HTTP/1.1\r\n" +
origin: renatoathaydes/rawhttp

RawHttp http = new RawHttp();
rawhttp.coreRawHttp<init>

Javadoc

Create a new instance of RawHttp using the default RawHttpOptions instance.

Popular methods of RawHttp

  • parseRequest
    Parses the given HTTP request.
  • parseResponse
    Parses the given HTTP response.
  • 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

  • Making http requests using okhttp
  • getApplicationContext (Context)
  • setScale (BigDecimal)
  • onCreateOptionsMenu (Activity)
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • InputStreamReader (java.io)
    A class for turning a byte stream into a character stream. Data read from the source input stream is
  • MalformedURLException (java.net)
    This exception is thrown when a program attempts to create an URL from an incorrect specification.
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t
  • Top plugins for Android Studio
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