Tabnine Logo
RawHttpResponse.getStatusCode
Code IndexAdd Tabnine to your IDE (free)

How to use
getStatusCode
method
in
rawhttp.core.RawHttpResponse

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

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: renatoathaydes/rawhttp

    .withBody(new StreamedChunkedBody(sender.getChunkStream())));
if (response.getStatusCode() != 200) {
  if (client instanceof Closeable) {
    ((Closeable) client).close();
  throw new RuntimeException("Server response status code is not 200: " + response.getStatusCode());
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

assertEquals(200, response.getStatusCode());
assertTrue(response.getBody().isPresent());
assertEquals("Hello RawHTTP!", response.getBody().get().decodeBodyToString(UTF_8));
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

System.out.println("RESPONSE:\n" + response);
assertEquals(200, response.getStatusCode());
assertTrue(response.getBody().isPresent());
origin: renatoathaydes/rawhttp

assertEquals(200, response.getStatusCode());
assertTrue(response.getBody().isPresent());
String textBody = response.getBody().get().decodeBodyToString(UTF_8);
rawhttp.coreRawHttpResponsegetStatusCode

Popular methods of RawHttpResponse

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

Popular in Java

  • Parsing JSON documents to java classes using gson
  • onRequestPermissionsResult (Fragment)
  • findViewById (Activity)
  • notifyDataSetChanged (ArrayAdapter)
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • UUID (java.util)
    UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • From CI to AI: The AI layer in your organization
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