package com.github.bot.curiosone.api;

import spark.Request;
import spark.Response;

/**
 * Utility class to convert requests and responses into audit logs.
 */
public class CorsUtil {
  private static final String ORIGINS = "*";
  private static final String METHODS = "GET, PUT, POST, DELETE, HEAD";
  private static final String HEADERS = "";

  /**
  * Default Constructor.
  */
  private CorsUtil() {}

  /**
   * Set headers for CORS options requests.
   * @param req The request object.
   * @param res The response object.
   * @return The response body.
   */
  public static String options(Request req, Response res) {
    String accessControlRequestHeaders = req.headers("Access-Control-Request-Headers");
    if (accessControlRequestHeaders != null) {
      res.header("Access-Control-Allow-Headers", accessControlRequestHeaders);
    }

    String accessControlRequestMethod = req.headers("Access-Control-Request-Method");
    if (accessControlRequestMethod != null) {
      res.header("Access-Control-Allow-Methods", accessControlRequestMethod);
    }

    return "OK";
  }

  /**
   * Set headers for CORS options requests.
   * @param req The request object.
   * @param res The response object.
   */
  public static void headers(Request req, Response res) {
    res.header("Access-Control-Allow-Origin", ORIGINS);
    res.header("Access-Control-Request-Method", METHODS);
    res.header("Access-Control-Allow-Headers", HEADERS);
  }
}

@@ -106,128 +106,299 @@
  to 
-convert requests and responses into audit logs.%0A */%0Apublic class CorsUtil %7B%0A  private static final String ORIGINS = %22*%22;
+manage CORS mechanism.%0A * Provides methods to set headers in Request objects.%0A */%0Apublic class CorsUtil %7B%0A%0A  /**%0A   * String representation of HTTP Origin header.%0A   */%0A  private static final String ORIGINS = %22*%22;%0A%0A  /**%0A   * String representation of HTTP Methods for RESTful Services.%0A   */
 %0A  p
@@ -465,16 +465,73 @@
 , HEAD%22;
+%0A%0A  /**%0A   * String representation of HTTP headers.%0A   */
 %0A  priva
@@ -635,32 +635,33 @@
 %0A%0A  /**%0A   * Set
+s
  headers for COR
@@ -1325,16 +1325,17 @@
    * Set
+s
  headers

improve CorsUtil javadoc