// Path: src/main/java/info/jdavid/ok/server/header/Connection.java
// @SuppressWarnings({ "WeakerAccess", "unused" })
// public final class Connection {
// 
//   private Connection() {}
// 
//   public static final String HEADER = "Connection";
// 
//   public static final String CLOSE = "Close";
//   public static final String KEEP_ALIVE = "Keep-Alive";
// 
// }


import javax.annotation.Nullable;
import info.jdavid.ok.server.header.Connection;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import okio.Buffer;
package info.jdavid.ok.server;




/**
 * The server request handler.
 */
@SuppressWarnings("WeakerAccess")
public interface RequestHandler {

  /**
   * Creates the server response for a given request.
   * @param clientIp the client ip.
   * @param secure whether the request is secure (over https) or not.
   * @param insecureOnly whether the server accepts only insecure connections or whether https is enabled.
   * @param http2 whether the request protocol is HTTP 2 (h2) rather than an HTTP 1.1.
   * @param method the request method (get, post, ...).
   * @param url the request url.
   * @param requestHeaders the request headers.
   * @param requestBody the request body.
   * @return the response for the request.
   */
  public Response handle(final String clientIp,
                         final boolean secure, final boolean insecureOnly, final boolean http2,
                         final String method, final HttpUrl url,
                         final Headers requestHeaders, @Nullable final Buffer requestBody);

  static class Helper {

    static Response handle(final RequestHandler handler,
                           final String clientIp,
                           final boolean secure, final boolean insecureOnly, final boolean http2,
                           final String method, final String path,
                           final Headers requestHeaders, @Nullable final Buffer requestBody) {
      final String h = requestHeaders.get("Host");
      if (h == null) {
        return new Response.Builder().
          statusLine(StatusLines.BAD_REQUEST).
// Path: src/main/java/info/jdavid/ok/server/header/Connection.java
// @SuppressWarnings({ "WeakerAccess", "unused" })
// public final class Connection {
// 
//   private Connection() {}
// 
//   public static final String HEADER = "Connection";
// 
//   public static final String CLOSE = "Close";
//   public static final String KEEP_ALIVE = "Keep-Alive";
// 
// }


// Path: src/main/java/info/jdavid/ok/server/RequestHandler.java
import javax.annotation.Nullable;
import info.jdavid.ok.server.header.Connection;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import okio.Buffer;

package info.jdavid.ok.server;




/**
 * The server request handler.
 */
@SuppressWarnings("WeakerAccess")
public interface RequestHandler {

  /**
   * Creates the server response for a given request.
   * @param clientIp the client ip.
   * @param secure whether the request is secure (over https) or not.
   * @param insecureOnly whether the server accepts only insecure connections or whether https is enabled.
   * @param http2 whether the request protocol is HTTP 2 (h2) rather than an HTTP 1.1.
   * @param method the request method (get, post, ...).
   * @param url the request url.
   * @param requestHeaders the request headers.
   * @param requestBody the request body.
   * @return the response for the request.
   */
  public Response handle(final String clientIp,
                         final boolean secure, final boolean insecureOnly, final boolean http2,
                         final String method, final HttpUrl url,
                         final Headers requestHeaders, @Nullable final Buffer requestBody);

  static class Helper {

    static Response handle(final RequestHandler handler,
                           final String clientIp,
                           final boolean secure, final boolean insecureOnly, final boolean http2,
                           final String method, final String path,
                           final Headers requestHeaders, @Nullable final Buffer requestBody) {
      final String h = requestHeaders.get("Host");
      if (h == null) {
        return new Response.Builder().
          statusLine(StatusLines.BAD_REQUEST).
          header(Connection.HEADER, Connection.CLOSE).